LNK2001 error (class using template)??? 
Author Message
 LNK2001 error (class using template)???

Dear Reader,

Look at the following piece of code:

/*****  Values.h *****/

template <class Type> class CValues
{
    private:
      Type value;

    public:
      void setValue( Type value );

Quote:
};

/***** Values.cpp *****/

#include "Values.h"

template<class Type>
void CValues<Type>::setValue( Type number)
{
  value = number;

Quote:
}

/***** Application.cpp *****/

#include <windows.h>
#include <windowsx.h>
#include <winbase.h>

#include "global.h"
#include "Values.h"

int WINAPI WinMain( HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int nCmdShow )
{
  CValues<double> values;
  values.setValue( 2.0 );
  return (0);

Quote:
}

Now I get the following error:

Application.obj : error LNK2001: unresolved external symbol "public: static
void __cdecl CValues<double>::setMinimum(double)"

What am I doing wrong?

Thank you,

Johan Machielse



Sat, 13 Mar 2004 20:55:49 GMT  
 LNK2001 error (class using template)???

There must be something in "global.h" which is causing the
problem as without it the code is fine.



Sat, 13 Mar 2004 22:38:04 GMT  
 LNK2001 error (class using template)???
Implementation of template methods must be in the .h file, together with
declaraion. Compiler must see the code at the point of instantiation.
--
With best wishes,
    Igor Tandetnik


Quote:
> Dear Reader,

> Look at the following piece of code:

> /*****  Values.h *****/

> template <class Type> class CValues
> {
>     private:
>       Type value;

>     public:
>       void setValue( Type value );
> };

> /***** Values.cpp *****/

> #include "Values.h"

> template<class Type>
> void CValues<Type>::setValue( Type number)
> {
>   value = number;
> }

> /***** Application.cpp *****/

> #include <windows.h>
> #include <windowsx.h>
> #include <winbase.h>

> #include "global.h"
> #include "Values.h"

> int WINAPI WinMain( HINSTANCE hInstance,
>                     HINSTANCE hPrevInstance,
>                     LPSTR lpCmdLine,
>                     int nCmdShow )
> {
>   CValues<double> values;
>   values.setValue( 2.0 );
>   return (0);
> }

> Now I get the following error:

> Application.obj : error LNK2001: unresolved external symbol "public:
static
> void __cdecl CValues<double>::setMinimum(double)"

> What am I doing wrong?

> Thank you,

> Johan Machielse



Sat, 13 Mar 2004 23:10:19 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Linking error LNK2001 when using template classes

2. LNK2001 Error with Template Classes in VC6

3. lnk2001 error when linking to non-inline methods of template classes

4. LNK2001 (class using template)

5. LNK2001 using Template class

6. HELP: LNK2001 error when using CList template

7. LNK2001 for template class constructor and destructor!

8. LNK2001 Error with template definition

9. LNK2001 Error with template definition

10. Template link error (LNK2001)

11. LNK2001 using templates

12. PLEASE HELP: TEMPLATE, LNK2001 error....

 

 
Powered by phpBB® Forum Software