You are not logged in.
Pages: 1
Hello!
I can't figure out why this code doesn't work?
#include <list>
template <class T> class Foo
{
public:
std::list<T>::iterator iter;
private:
std::list<T> elements;
};
int main (void)
{
return 0;
}
This is g++ output:
kod.cpp:6: error: type ‘std::list<T, std::allocator<_Tp1> >’ is not derived from type ‘Foo<T>’
kod.cpp:6: error: expected ‘;’ before ‘iter’
Can someone explain it for me please?
Offline
One more question. I noticed problem while implementing template class. Everything compiles and work fine when I put both tmeplate's declaration and implementation in header file. Linker fails when I leave declaration in header and move implementation to source file.
Is it normal behavior...?
Offline
I don't use C++ and templates much but it seems to me they would have to work in a fashion similar to inline code and as such would have to be in a header file and not a normal source file (unless that is the also the only place it is used) as otherwise there is no way to know which declarations to generate from the templates until one sees the instantiations (which cannot be done unless it is in a header file that is included in all source files that use the a template instantiation).
Offline
Pages: 1