Re: class template



rich wrote:
> Hi there,
>
> I defined a class template (MyClass) and some member variables and
> functions, as following:
>
> template<class T1, class T2>
> class MyClass
> {
> ...
> struct m_variable
> {
> ...
> };
> m_variable* MyFunc(m_variable* pv1, m_variable* pv2);
> ...
> }
>
> template <class T1, class T2>
> MyClass<T1, T2>::m_variable* MyClass<T1,
> T2>::MyFunc(MyClass::m_variable* pv1, MyClass::m_variable* pv2)
> {
> ...
> m_variable* pv;
> ...
> return pv;
> }
>
> It compiles with VC++ v6.0, but doesn't compile with VC++ v7.0 (.Net
> 2003). Anybody can give me some advice to modify the code to make it
> compile.

Please post either or both of: some actual (complete) code that doesn't
compile and the exact error(s) that you're getting from the compiler.

In all likelihood, you need to add the 'typename' keyword in a few places to
make the code legal C++ (VC6 didn't enforce that rule, VC7.1 does).

e.g.

template <class T1, class T2>
typename MyClass<T1, T2>::m_variable* MyClass<T1, T2>::MyFunc(
MyClass::m_variable* pv1,
MyClass::m_variable* pv2
)

-cd


.



Relevant Pages

  • Implication of project dependencies
    ... I am working on a project with VC++ 2003 and it compile & link well, ... myclass & myclass::GetInstance ... responsible of that are the project dependencies. ... this manual reference and checked the project myclass in the project ...
    (microsoft.public.vsnet.ide)
  • Implication of project dependencies
    ... I am working on a project with VC++ 2003 and it compile & link well, ... myclass & myclass::GetInstance ... responsible of that are the project dependencies. ... this manual reference and checked the project myclass in the project ...
    (microsoft.public.vc.ide_general)
  • Re: Organising classes in C# in Visual Studio ?
    ... > Visual Studio copying the Solution to the folder that adds the MyClass? ... > don't want to compile it to a dll - I better like to have a link or ... > something to the source code file itself! ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Strange problem about constructor
    ... ie: myclass{... ... Get this code to compile and show us the problem. ... >> A(int a, int b) ...
    (comp.lang.cpp)
  • Object to array conversion oddity
    ... class Myclass() { ... public function __sleep{ ... "If you convert an object to an array, you get the properties (member variables) of that object as the array's elements. ...
    (php.general)