Re: [Dev-C++] templates + linker error
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2008-05-26 18:57:18
|
Think a bit about it.
What code to you suggest that the compiler should enerate when it compiles
calc.cpp? If the compiler does not know that other source files will use
the template parameter "double", how will the compiler then be able to add
a "double" version of multiply when it compiles calc.cpp?
Remember that it is the compiler, not the linker, that produces the
runnable code. The linker will have no use for an object file that doesn't
contain instantiated template functions.
/pwm
On Mon, 26 May 2008, Lloyd wrote:
> 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
>
> -------------------------------------------------------------------------
> 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
>
|