Link to home
Start Free TrialLog in
Avatar of s_lavie
s_lavie

asked on

Class Template - Linker Error

Hi,
I wrote a code in c++, using a template class.
When I put all function and declaration in one file (no project) it was just fine. But when I divided it to few files (using project) I had a linker error:
"undefined symbol a<int>::show_num() in module appl.cpp"
when "a" is the class template, and "show_num()" is a public function in it.
the same goes very well when I don't use the template.

Any idea ????????

please if can add an example.
Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Norbert
Norbert
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

>> You can't split the functions of a template class to a cpp file
You can, but only if it will be used in only that .cpp file.   If a template is used by multiple .cpp files, but the entire template in a .h file.  If the template is useed on only one .cpp file, you can place it in the .cpp file  (In that case, I would put everything for the template in the ,cpp file, you wouldn't want a .h for that.)
Avatar of s_lavie

ASKER

Adjusted points to 30