views:

168

answers:

1

I have a traits class that's used for printing out different character types:

template <typename 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)

+1  A: 

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>).

Johannes Schaub - litb