Click to See Complete Forum and Search --> : Problem with templates


damaster
April 13th, 1999, 03:43 AM
I have some (weird?) problem with a template class I'm writing. First, I have a template class called CTree for storing generic data. Then, I declare an instance of it. When I link the whole program, I get an error: external symbol not defined "public: int const __thiscall IcdTree::AddNode ... ".
What could that be? The method it references is defined, and the .cpp file is included in the project.

Thanks, Martin

Franky Braem
April 13th, 1999, 09:21 AM
Is the sourcecode of your templateclass written in the headerfile of your template ?

damaster
April 14th, 1999, 02:38 AM
All the code for the template class itself is in the header file.
To specify the problem: I have a class template called CTree <T>, which implements a generic tree. In another class, say CXYTree, I instantiate it with a member variable:
CTree<struct Something> m_tMem.
The linker error occurs when I try to use a member of CXYTree in my document, e.g. CXYTree::AddNode(...). The linker then complains that the symbol CXYTree::AddNode(Something const &) is not defined.

Franky Braem
April 14th, 1999, 03:30 AM
You have to call the method of your member variable:

m_tMem.AddNode(...);