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)
您需要向类提供->
运算符MyIterator
,如下所示:
T *operator->() {
return data;
}
Run Code Online (Sandbox Code Playgroud)