Re: [Dev-C++] templates + linker error
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Lloyd <ll...@cd...> - 2008-05-26 09:52:20
|
The reason for the error is you are not passing the obj file of calc.cpp to the linker. Make appropriate settings in DevCpp. I think, you have to add calc.cpp to your project. Sorry I dont use DevCpp. On Sun, 2008-05-25 at 16:42 -0500, Jorge Guevara wrote: > > i have 3 source calc.h calc.cpp and principal.cpp (i compilated it > with devcpp) > > i have this error: > In function `main': > [Linker error] undefined reference to `calc<double>::multiply(double, > double)' > ld returned 1 exit status > [Build Error] ["Proyecto] Error 1 > > somebody could help me please :) > > /********calc.h******/ > #ifndef _CALC_H > #define _CALC_H > > template <class A_Type> class calc > { > public: > A_Type multiply(A_Type x, A_Type y); > A_Type add(A_Type x, A_Type y); > > }; > > #endif > > /****calc.cpp******/ > #include "calc.h" > #include <iostream> > using namespace std; > > template <class A_Type> A_Type calc<A_Type>::multiply(A_Type x,A_Type > y) > { > return x*y; > } > template <class A_Type> A_Type calc<A_Type>::add(A_Type x, A_Type y) > { > return x+y; > } > > > /******principal.cpp*****/ > #include "calc.h" > #include <iostream> > #include <cstdlib> > > using namespace std; > > int main() > { > calc <double> a_calc_class; > double a, b; > a=4.3; > b=3.4; > a_calc_class.multiply(a,b); > > system("PAUSE"); > return EXIT_SUCCESS; > } > /***************************/ > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ Dev-cpp-users mailing list Dev...@li... TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm https://lists.sourceforge.net/lists/listinfo/dev-cpp-users ______________________________________ Scanned and protected by Email scanner |