typedef, template, and pointer to vector
18 Jul
2003
18 Jul
'03
08:04
Hi, Why this code won't compile? #include <iostream> #include <vector> using namespace::std; template<typename T> class Entry { public: T data; }; int main() { typedef Entry<int> ei; vector<ei*>* v = new vector<ei*>(); ei* ONE = new ei(); ONE->data = 1; v->push_back(ONE); ei* tmp = v[0]; //Error here... cout << tmp->data << endl; return 0; } When I compiled the above code: test2.cpp:20: error: cannot convert `std::vector<main()::ei*, std::allocator<main()::ei*> >' to `main()::ei*' in initialization However, if I change v to nonpointer (i.e. vector<ei*> v), that code will compile. Any ideas? TIA. -- -- Verdi March --
7833
Age (days ago)
7833
Last active (days ago)
1 comments
1 participants
participants (1)
-
Verdi March