// This is a header file.
class MyClass; // It can be forward declared because the function uses reference.
// However, how can I do forward declaraion about std::wstri
I don't think avoiding #include
namespace std {
template
struct char_traits;
template
struct allocator;
template
struct basic_string;
typedef basic_string, allocator >
wstring;
}
// simple test that it's compatible:
std::wstring *p; // incomplete type at this point, but you can have a pointer
#include
int main() {
std::wstring s = L"Hello, world!";
p = &s;
return 0;
}
You have to be careful of default parameters; in particular, this would not work:
namespace std {
template
struct char_traits;
template
struct allocator;
template,
class Allocator=allocator >
struct basic_string;
typedef basic_string wstring;
}
#include
Compiled with the include shows the incompatibility:
In file included from /usr/include/c++/4.4/string:41,
from example.cpp:15:
/usr/include/c++/4.4/bits/stringfwd.h:52: error: redefinition of default argument for ‘class _Traits’
example.cpp:8: note: original definition appeared here