#include <map>
#include <iostream>
#include <string>
using namespace std;
template <class T>
class Foo{
public:
map<int, T> reg;
map<int, T>::iterator itr;
void add(T str, int num) {
reg[num] = str;
}
void print() {
for(itr = reg.begin(); itr != reg.end(); itr++) {
cout << itr->first << " has a relationship with: ";
cout << itr->second << endl;
}
}
};
int main() {
Foo foo;
Foo foo2;
foo.add("bob", 10);
foo2.add(13,10);
foo.print();
return 0;
}
私はエラーを取得する:
type std::map<int, T, std::less<int>, std::allocator<std::pair<const int, T> > > is not derived from type Foo<T>
私はC++のテンプレート使ったことがない - これは何を意味するのか?
1:
編集、ここにコンパイルされ、ローカルで実行されるコードの修正版です。次回はそれがどの行にあるのかを示します(これを達成するには、ソースコードにコメントを付けるのが良い方法です)。 –