1,VS2013 

错误 1 error C2556: “const int &Array<int>::operator [](int)”: 重载函数与“int &Array<int>::operator [](int)”只是在返回类型上不同 

出错代码:

VS2013 error C2556: “const int &Array<int>::operator [](int)”: 重载函数与“int &Array<int>::operator [](int)”只是在返回类型上不同

出错原因:

在 C++ 中,两个只有返回类型不同的函数不可以实现重载,重载只是参数类型不同才可以重载。想知道这种情况下如何实现重载,可点击这里

错误解决:

把第二个改为:const T& operator[] (int) const;即可

因为 const 类型的函数可以和一般函数实现重载操作。只读函数和非只读函数可以形成重载关系。

相关文章:

  • 2021-08-28
  • 2022-12-23
  • 2021-10-21
  • 2022-12-23
  • 2021-07-08
  • 2021-12-05
  • 2021-12-14
  • 2021-06-15
猜你喜欢
  • 2021-09-06
  • 2022-12-23
  • 2022-01-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案