【问题标题】:I do not understand this C++ error - error C2101: '&' on constant我不明白这个 C++ 错误 - 错误 C2101: '&' on constant
【发布时间】:2011-11-19 11:45:20
【问题描述】:

据说这段代码可以与 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::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

文件

aaa.h:52          virtual const Type aMethod() const { return Type(); }

bbb.h:79          AClass<const BClass&> blahblahblah_;

【问题讨论】:

  • 这个可爱的小虫子。我喜欢它。
  • 这是最新版本吗?似乎 VS2010 已经修改了这个错误信息。
  • 好;它在这里有点垃圾诊断。
  • 嗯,刚启动VS2010,还是比较差。

标签: c++ templates visual-c++ compiler-errors


【解决方案1】:

构造T() 其中 T 是一个引用类型是无效的,并且没有任何意义。某些版本的 gcc 错误地接受它。

【讨论】:

  • GCC 4.5.1 正确,包括错误消息:ideone.com/DOHb3 "error: invalid value-initialization of reference types"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-12
  • 1970-01-01
  • 1970-01-01
  • 2011-12-19
  • 1970-01-01
相关资源
最近更新 更多