Connecting Tech Pros Worldwide Forums | Help | Site Map

linking problem with nested class in template class

Dominik Fritz
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi,

I have a template class which contains a nested class. The .cpp file is
included at the end of the header file. If I write the implementation of
a member function of my nested class in this .cpp file (i.e. not inside
the declaration of the class) the linker complains about a missing
symbol. If I write the implementation inside the declaration everything
is fine.
Any Ideas why this happens (I use VC++6)?


// myclass.h


template <typename T>
class myclass
{
class mynestedclass
{
void memberfunction () ;
}

}

#include myclass.cpp


//myclass.cpp

template <typename T>
void myclass<T>::mynestedclass::memberfunction ()
{
// some code
}

Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 23 '05

re: linking problem with nested class in template class


Dominik Fritz wrote:[color=blue]
> I have a template class which contains a nested class. The .cpp file is
> included at the end of the header file. If I write the implementation of
> a member function of my nested class in this .cpp file (i.e. not inside
> the declaration of the class) the linker complains about a missing
> symbol. If I write the implementation inside the declaration everything
> is fine.
> Any Ideas why this happens (I use VC++6)?[/color]

Because VC++ v6 is really bad with templates. Put the definition inside
the class. Upgrade your compiler ASAP.
[color=blue]
> [...][/color]
Dominik Fritz
Guest
 
Posts: n/a
#3: Jul 23 '05

re: linking problem with nested class in template class


Hi Victor,

Victor Bazarov schrieb:[color=blue]
> Dominik Fritz wrote:
>[/color]
[...][color=blue]
>
> Because VC++ v6 is really bad with templates. Put the definition inside
> the class. Upgrade your compiler ASAP.[/color]

thanks for your fast reply. Unfortunately there are other constraints
why I have to use VC++ 6 :(

Dominik

Closed Thread