I have a string class that, unsurprisingly, uses a different implementation depending on whether or not UNICODE is enabled.
#ifdef UNICODE
typedef StringUTF16 StringT;
#else
typedef StringUTF8 StringT;
#endif
This works nicely but I currently have a problem where I need to forward declare the StringT typedef. How can I do this?
I can't do typedef StringT;
so it makes forward declaration tricky. Is it possible to do a forward declare of this typedef'd type without having to past the code above into the top of the header file?
Follow the example set by the iosfwd standard header. Write a header file that contains this, and call it StringTFwd.h
class StringUTF16;
class StringUTF8;
#ifdef UNICODE
typedef StringUTF16 StringT;
#else
typedef StringUTF8 StringT;
#endif
At least this is reusable and doesn't ugly up the headers that refer to it.
You can't. (Rational: you can use typedef to define an alias for a basic type and those may use different ABI conventions depending on the precise type).
Can't you forward declare both StringUTF16 and StringUTF8 and then use your #idef
?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.