Error using traits class.: "expected constructor destructor or type conversion before '&' token"
I have a traits class that's used for printing out different character types:
template <typename T&g开发者_开发百科t;
class traits {
public:
static std::basic_ostream<T>& tout;
};
template<>
std::ostream& traits<char>::tout = std::cout;
template<>
std::wostream& traits<unsigned short>::tout = std::wcout;
gcc (g++) version 3.4.5 (yes somewhat old) is throwing an error: "expected constructor destructor or type conversion before '&' token"
And I'm wondering if there's a good way to resolve this.
(it's also angry about _O_WTEXT so if anyone's got some insight into that, I'd also appreciate it)
wchar_t
is a different type than unsigned short
. You have to use
template<>
std::wostream& traits<wchar_t>::tout = std::wcout;
Even though they may use the same representation, they are nontheless different integer types. Much like the three of char
, signed char
and unsigned char
.
Also be sure you included the correct header (<ostream>
or include <iostream>
).
精彩评论