错误C2662 常量函数const

错误    C2662    “int Vector<int>::size(void)”: 不能将“this”指针从“const Vector<int>”转换为“Vector<int>& ”

问题:用常量对象调用非常量成员函数

错误C2662 常量函数const

 

知识点:

错误C2662 常量函数const

常量函数:用const修饰,表明在该函数内部,this指针中包含的成员变量无法更改数值,this调用的函数必须是const修饰的常量函数。