C++ 我不明白这个C++;错误-错误C2101:&x27&';论常数
这段代码应该与GCC一起工作——我正试图让它与Visual Studio一起工作。我不知道代码是否有问题,或者我没有正确处理端口C++ 我不明白这个C++;错误-错误C2101:&x27&';论常数,c++,templates,visual-c++,compiler-errors,C++,Templates,Visual C++,Compiler Errors,这段代码应该与GCC一起工作——我正试图让它与Visual Studio一起工作。我不知道代码是否有问题,或者我没有正确处理端口 1>c:\somepath\aaa.h(52): error C2101: '&' on constant 1> c:\somepath\aaa.h(52): while compiling class template member function 'const blahblah::Message something::ACl
1>c:\somepath\aaa.h(52): error C2101: '&' on constant
1> c:\somepath\aaa.h(52): while compiling class template member function 'const blahblah::Message something::AClass<Type>::aMethod(void) const'
1> with
1> [
1> Type=const lala::BClass&
1> ]
1> c:\somepath\bbb.h(79) : see reference to class template instantiation 'something:AClass<Type>' being compiled
1> with
1> [
1> Type=const lala::BClass&
1> ]
1> MyApplication.cpp
1>c:\somepath\aaa.h(52):错误C2101:“&”在常量上
1> c:\somepath\aaa.h(52):编译类模板成员函数“const blahblah::Message something::AClass::aMethod(void)const”时
1> 与
1> [
1> 类型=常量lala::B类&
1> ]
1> c:\somepath\bbb.h(79):请参阅对正在编译的类模板实例化'something:AClass'的引用
1> 与
1> [
1> 类型=常量lala::B类&
1> ]
1> MyApplication.cpp
档案
aaa.h:52 virtual const Type aMethod() const { return Type(); }
bbb.h:79 AClass<const BClass&> blahblahblah_;
aaa.h:52虚拟常量类型aMethod()常量{return Type();}
bbb.h:79 A类blahblahblah;
构造T()
其中T是引用类型是无效的,没有任何意义。gcc的某些版本错误地接受了它。这是一个可爱的小错误。我喜欢。这是最近的版本吗?看起来VS2010已经修改了这个错误消息;这里的诊断有点垃圾。嗯,刚刚启动了VS2010,但仍然很糟糕。GCC 4.5.1正确地进行了诊断,包括错误消息:“错误:引用类型的无效值初始化”