Reputation: 105213
Why I can't compile this code?
#include <map>
using namespace std;
class MyTest {
template<typename T> void test() const;
};
template<typename T> void MyTest::test() const {
map<string, T*> m;
map<string, T*>::const_iterator i = m.begin();
}
My compiler says:
In member function ‘void MyTest::test() const’:
test.cpp:8: error: expected `;' before ‘i’
What is it about? Many thanks in advance!
Upvotes: 0
Views: 219
Reputation: 23198
You have a dependent name, you need to append typename
to the const_iterator because its type depends on the type of T
.
template<typename T> void MyTest::test() const {
map<string, T*> m;
typename map<string, T*>::const_iterator i = m.begin();
}
Upvotes: 6