"' - >'的基本操作数有非指针类型"但它是指针

Eas*_*mer 0 c++ inheritance templates stl std-pair

这是我的代码.(我简化了这一点,通常有很多成员函数,但错误仍然相同,所以我简化了它.)

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;
}
Run Code Online (Sandbox Code Playgroud)

Ada*_*hon 6

您需要向类提供->运算符MyIterator,如下所示:

T *operator->() {
    return data;
}
Run Code Online (Sandbox Code Playgroud)

  • @EasterGamer,在你完成之后,我建议[CodeReview.se]让它变得更好. (2认同)