passing xxx as 'this' argument of xxx discards qualifiers
清泛原创
这是由于常量对象调用了非常量成员函数引起的错误,错误原因在于常量对象只能调用常量成员函数(因为常量成员函数约定不对非静态成员进行修改).
这个例子中,加入set的StudentT对象都变成const对象了,那么调用getId等方法时只能调用其const版本,因为没有定义这个版本,因此编译器提示错误.
解决方法就是将getId和getName方法声明为const成员,即在函数末尾加上const关键字。
对我有用
(3)
100%
没啥用
(0)
0%
上一篇:error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private ios_base(const ios_base&); synthesized method ‘std::basic_ostream
下一篇:error: cannot dynamic_cast ‘b’ (of type ‘class Base*’) to type ‘class Derived