_foo referenced from _bar is undefined (again)



Hi all

I get this linker error in my project and I'm unable to find the reason
for it. I checked all topics in this list but without any success. The
problem looks like this (this is a simplified version with just the
basic code related to the error):

---- Arrays.h ----

template <class T>
class Array
{
public:
Array();
};

---- Arrays.cpp ----

template <class T>
Array<T>::Array()
{
}

---- MyApp.cpp ----

#include "Arrays.h"

void SomeFunc()
{
Array<int>* array = new Array<int>();
}

This compiles ok, but the linker complains with the error:
"MyApp.cpp: 'Array<int>::Array()' referenced rom 'SomeFunc' is
undefined."

I use CW 8.2 and SDK 5r3. I can solve the problem by moving all Array
related functions to the Array.h and inline them, but it looks like I
always end with this problem after a while (with a different class).
What am I missing?

.



Relevant Pages

  • Re: templates, C++, and LNK2019
    ... > I've found some other posts that deal with this linker error, ... Separate compilation of template implementations are not supported by ... template" in the header file. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: templates, C++, and LNK2019
    ... >> I've found some other posts that deal with this linker error, ... > template" in the header file. ...
    (microsoft.public.dotnet.languages.vc)
  • linker needs .cpp when using template class
    ... I am confused by an linker error given by VC6.0 sp5. ... I defined a template class. ... .cpp file before the linker error goes away. ... is this a VC limitation or is this a template limitation? ...
    (comp.lang.cpp)
  • Re: Very basic question.
    ... A linker error means that you've failed to define the entity named. ... template func, in the case when T equals int. ... It would also be worth looking around and seeing where the method func2 is ...
    (comp.lang.cpp)