I have a function which returns a type std::istringstream
inside one of my classes. To avoid #include <sstream>
in my header file, I wrote the prototype class istringstream;
at the top of my header file and wrote the return type as istringstream
. When defining the function in my cpp file, I wrote the return type as std::istringstream
.
I now have ambiguity issues where I am unable to use istringstream
without declaring it as std::istringstream
, although I have using std::istringstream
.
What is the best practice here? I had always learned to declare prototypes instead of including the full header when possible.
Here is an example for clarity:
example.h
class istringstream;
istringstream myFunction();
example.cpp
#include "example.h"
using std::istringstream;
std::istringstream myFunction(){} // istringstream is ambiguous
Update:
Answered in comments -> it is not recommended to forward declare and is in fact undefined behavior.