I have realized a template class Stack.
In function main I have an instance:
Stack<int> oneStack;
If I implement the class in the file that contains main all is ok. If I split the program in:
main.cpp // contains function main
Stack.hpp // contains the interface of Stack
Stack.cpp // contains the implemantation of Stack
I obtain the following linker error:
undefined reference to `Stack<int>::Stack(void)'
I have found that I have to delay the translation of the template class. In Borland C++ I have to insert in Stack.cpp:
#pragma option -Jgd
and in main.cpp:
#pragma option -Jgx
What I have to do in Dev-c++ (rel. 4.9.6.0)?
Thanks.
by Francesco Pagano (fpagano@pep.it)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2002-12-05
i assume you also added #include "Stack.hpp" to mai.cpp, when you move to multiple files. Asumming Stack.h is in the same directory as main.cpp, else include the relative path also.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have realized a template class Stack.
In function main I have an instance:
Stack<int> oneStack;
If I implement the class in the file that contains main all is ok. If I split the program in:
main.cpp // contains function main
Stack.hpp // contains the interface of Stack
Stack.cpp // contains the implemantation of Stack
I obtain the following linker error:
undefined reference to `Stack<int>::Stack(void)'
I have found that I have to delay the translation of the template class. In Borland C++ I have to insert in Stack.cpp:
#pragma option -Jgd
and in main.cpp:
#pragma option -Jgx
What I have to do in Dev-c++ (rel. 4.9.6.0)?
Thanks.
by Francesco Pagano (fpagano@pep.it)
i assume you also added #include "Stack.hpp" to mai.cpp, when you move to multiple files. Asumming Stack.h is in the same directory as main.cpp, else include the relative path also.