使用特征类时出错:“预期的构造函数、析构函数或类型转换之前'&”令牌”
我有一个用于打印不同字符类型的特征类:
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(是的有点旧)抛出一个错误: “‘&’之前预期有构造函数、析构函数或类型转换token”
我想知道是否有一个好的方法来解决这个问题。
(它也对 _O_WTEXT 感到愤怒,所以如果有人对此有一些见解,我也会很感激)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
wchar_t
与unsigned Short
是不同的类型。您必须使用即使它们可能使用相同的表示形式,但它们仍然是不同的整数类型。很像
char
、signed char
和unsigned char
这三个字符。另请确保包含正确的标头(
或包含
)。wchar_t
is a different type thanunsigned short
. You have to useEven though they may use the same representation, they are nontheless different integer types. Much like the three of
char
,signed char
andunsigned char
.Also be sure you included the correct header (
<ostream>
or include<iostream>
).