Forward declaration of an STL class (wstring)?

Started by
2 comments, last by the_edd 15 years, 5 months ago
Is there a way to do this. i have a c++ class I am placing in a win32 dll it uses wstrings in some of its function prototypes for parameters, no returns. I want to then wrap this in a C++ CLR Class Lib but i want this class to have as little reference to STL as possible ie none if possible :p, and to that end don't want to include the <string> header in my win32 dll c++ header. I'm assuming this should be fine because a wstring can accept a terminated char array on construction which is what the calling class will pass. So in short is there a way to provide a forward declaration of wstring without including <string>. I am going to use wchar_t* in the mean time but i am curious now.
Innovation not reiterationIf at any point I look as if I know what I'm doing don't worry it was probably an accident.
Advertisement
Because std::wstring is actaully a typedef of a template instantiation (typedef std::basic_string<wchar_t> wstring;), it is quite difficult to provide a forward declaration - as with any template class.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

ah, ya was thinking it was because it was a template class, and that it would not be simple.

I really need to get round to learning templates some time :$, so much else to learn though

I am just going to go with char array. Wasn't doing any string operations anyway.
Innovation not reiterationIf at any point I look as if I know what I'm doing don't worry it was probably an accident.
Quote:Original post by swiftcoder
Because std::wstring is actaully a typedef of a template instantiation (typedef std::basic_string<wchar_t> wstring;), it is quite difficult to provide a forward declaration - as with any template class.


The C++ standard forbids forward declarations of pretty much anything in the std namespace :(

I think the reason being that implementations are free to add additional arguments with default arguments and similarly for template parameters.

The only concession is the <iosfwd> header for streams.

This topic is closed to new replies.

Advertisement