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

    1,VS2013 

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

    出错代码:

    出错原因:

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

    错误解决:

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

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

    所有博文均为原著,如若转载,请注明出处!
  • 相关阅读:
    小程序 scroll-view 中文字不换行问题
    模块
    网络编程
    元类
    day24
    day23
    day22
    day21
    day18
    day17
  • 原文地址:https://www.cnblogs.com/zpcoding/p/10484943.html
Copyright © 2011-2022 走看看