I have designed a package with several files, which is listed bellow
base.cpp & base.hpp - define the template class base
tree.cpp & tree.hpp - define the class tree derived from base<int>
client.cpp & client.hpp - define the class client derived from tree
main.cpp - the main function instantiate client and run
All these files are compiled successfully, but there's a linker error " [Linker error] undefined reference to `base<int>::bas e_run()' ".
However, I have defined this function in base.cpp, and all .cpp files are added to the project. I use IDE Dev-C++ 4.9.9.2. I don't know why the linker cannot find this function. When I get ride of the template, then problem solved. But I really need the class "base" to be a template class. When I use the template but melt all these files into one file, problem also solved. But I don't like that.
I have made the program to be very small (doing nothing, only shows the problems) and attached it with this note in the file problem_example .zip.
Can anybody tell me why this happen? what's wrong with template class?
thanks a lot
base.cpp & base.hpp - define the template class base
tree.cpp & tree.hpp - define the class tree derived from base<int>
client.cpp & client.hpp - define the class client derived from tree
main.cpp - the main function instantiate client and run
All these files are compiled successfully, but there's a linker error " [Linker error] undefined reference to `base<int>::bas e_run()' ".
However, I have defined this function in base.cpp, and all .cpp files are added to the project. I use IDE Dev-C++ 4.9.9.2. I don't know why the linker cannot find this function. When I get ride of the template, then problem solved. But I really need the class "base" to be a template class. When I use the template but melt all these files into one file, problem also solved. But I don't like that.
I have made the program to be very small (doing nothing, only shows the problems) and attached it with this note in the file problem_example .zip.
Can anybody tell me why this happen? what's wrong with template class?
thanks a lot
Comment