tags:

views:

248

answers:

4

Hey,

I am trying to compile this :

template <class T, class U = myDefaultUClass<T> >
class myClass{
 ...
};

Although it seems quite intuitive to me it is not for my compiler, does anyone knows how to do this ?

edit : Ok, the problem was not actually coming from this but from a residual try ... Sorry about this, thanks for your answers anyway.

+3  A: 

Compiles fine with Comeau...

Assaf Lavie
+4  A: 

The following works for me using g++. Please post more code, the error messages you are getting and the compiler version.

class A {};

template <class T> class T1 {};

template <class T, class U = T1<T> > class T2 {
};

T2 <A> t2;
anon
And the compiler info.
Anonymous
I use g++ also, I guess I simplefied too much, let me find out why
Ben
A: 

This works on MSVC 9.0 :

template < class T >
class UClass
{
private:
    T m_data;
};

template < class T, class U = UClass< T > >
class MyClass 
{
public:
    const U& data() const { return m_data; }
private:

    U m_data;
};


int main()
{
    MyClass< int > test;

    const UClass<int>& u = test.data();

    return 0;
}
Klaim
A: 

It's either that your compiler isn't standard complaint, or you made one of these mistakes:

  1. myDefaultUClass is not a template
  2. myDefaultUClass isn't defined

because the following works fine in G++:

class myDefaultUClass{};

template <class T, class U = myDefaultUClass >
class myClass{
 //...
};
Lawand