"base operand of ‘->’ has non-pointer type" 但它是指针
"base operand of ‘->’ has non-pointer type" But It is pointer
这是我的代码。(我简化了这个,通常有很多成员函数,但错误仍然存在,所以我简化了。)
template <class K,class V>
class MyMap:public MySet<pair<K, V> >{};
int main(void){
MyMap<int,int> map1;
MyMap<int,int>::MyIterator it;
it=map1.begin();
cout<<it->first<<endl;
return 0;
}
您需要向 MyIterator
class 提供 ->
运算符,如下所示:
T *operator->() {
return data;
}
这是我的代码。(我简化了这个,通常有很多成员函数,但错误仍然存在,所以我简化了。)
template <class K,class V>
class MyMap:public MySet<pair<K, V> >{};
int main(void){
MyMap<int,int> map1;
MyMap<int,int>::MyIterator it;
it=map1.begin();
cout<<it->first<<endl;
return 0;
}
您需要向 MyIterator
class 提供 ->
运算符,如下所示:
T *operator->() {
return data;
}