我正在尝试实现一个简单的复制构造函数:
template<typename T>
MyClass<T>::MyClass(const MyClass<T> &other) {
MyIterator<T> it = other.begin();
//...
};
成员函数主体中的那一行会产生此错误:
Cannot convert this pointer from const Class to Class&
我尝试了 const_cast 的东西,但没有成功。
最佳答案
您的 begin
方法显然是非 const 方法,但您尝试在 const 对象上调用它。
关于c++ - 无法将此指针从 const Class<T> 转换为 Class<T>&,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24391973/