Problem with templates...

K

Kostas Katsamakas

I have created a template class with its implementation in a .cpp file
and its declaration in a .h
Compilation finishes successfully and i get errors during linking with
unresolved externals. The
reported externals are methods of the template class. If i put the
implementation of these methods
in the header file, after the declaration of the template class then
everything goes fine.
What could be wrong. I have the feeling that it could be something really
easy that i'm missing
at the moment.
 
D

David White

Kostas Katsamakas said:
I have created a template class with its implementation in a .cpp file
and its declaration in a .h
Compilation finishes successfully and i get errors during linking with
unresolved externals. The
reported externals are methods of the template class. If i put the
implementation of these methods
in the header file, after the declaration of the template class then
everything goes fine.

In the header is where they are supposed to be. The compiler can't compile
the implementations of the template class's member functions for different
template parameters unless it can see the source code for the functions at
all the places the template is used.

DW
 
K

Kevin Goodsell

Kostas said:
I have created a template class with its implementation in a .cpp file
and its declaration in a .h
Compilation finishes successfully and i get errors during linking with
unresolved externals. The
reported externals are methods of the template class. If i put the
implementation of these methods
in the header file, after the declaration of the template class then
everything goes fine.
What could be wrong. I have the feeling that it could be something really
easy that i'm missing
at the moment.

http://www.parashift.com/c++-faq-lite/containers-and-templates.html#faq-34.12
http://www.parashift.com/c++-faq-lite/containers-and-templates.html#faq-34.14

-Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top