我不明白这个C++错误 - 错误 C2101:常量'&'

I do not understand this C++ error - error C2101: '&' on constant

本文关键字:错误 常量 明白 C2101 C++      更新时间:2023-10-16

这段代码应该与GCC一起工作-我正试图让它与Visual Studio一起工作。我不知道代码是否有问题,或者我在端口上没有做正确的事情。

1>c:somepathaaa.h(52): error C2101: '&' on constant
1>          c:somepathaaa.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:somepathbbb.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
文件

aaa.h:52          virtual const Type aMethod() const { return Type(); }
bbb.h:79          AClass<const BClass&> blahblahblah_;

构造T为引用类型的T()是无效的,并且没有意义。