Jump to content


Template and Visual C++


4 replies to this topic

#1 GFalcon

    New Member

  • Members
  • Pip
  • 3 posts

Posted 14 September 2005 - 07:28 PM

Hi everybody,

I have a little problem with templates under visual c++ (.NET), actually I try to implement a templated method in a templated class:

template <typename T>
class MyClass
{
template<typename T2>
T2& MyMethod();
};

I want to define the method, in an other file, this way:

template <typename T>
template <typename T2>
T2& MyClass<T>::MyMethod()
{
... method implementation
}

It works fine with gcc compiler but does not with visual.

What am i doing wrong ?

#2 anubis

    Senior Member

  • Members
  • PipPipPipPip
  • 2225 posts

Posted 14 September 2005 - 07:46 PM

Are you implementing the methods as inline ? It won't work if you put the methods into a .cpp file (at least not if you don't exclude the file from compilation).
If Prolog is the answer, what is the question ?

#3 GFalcon

    New Member

  • Members
  • Pip
  • 3 posts

Posted 14 September 2005 - 07:51 PM

It is not inlined, the method is in fact defined in another file that is included at the end of my header file that declares the class.

#4 bramz

    Valued Member

  • Members
  • PipPipPip
  • 189 posts

Posted 14 September 2005 - 08:12 PM

My guess is that you're using .NET 2002 (the 7.0). you can't define templated methods out of line in that one (although it's perfectly legal in C++). You can either upgrade to .NET 2003 or define it in the class definition, like this:


template <typename T>

class MyClass

{

template<typename T2>

T2& MyMethod()

{

... method implementation

}

};


I hope this helps,
Bramz
hi, i'm a signature viruz, plz set me as your signature and help me spread :)
Bramz' warehouse | LiAR isn't a raytracer

#5 GFalcon

    New Member

  • Members
  • Pip
  • 3 posts

Posted 14 September 2005 - 08:17 PM

bramz said:

My guess is that you're using .NET 2002 (the 7.0). you can't define templated methods out of line in that one (although it's perfectly legal in C++).

So that's why :)
I'll just have to upgrade my compiler then

Thanks for the answer





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users