Reputation: 7628
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.
Upvotes: -1
Views: 795
Reputation:
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;
Upvotes: 5
Reputation: 1112
It's either that your compiler isn't standard complaint, or you made one of these mistakes:
because the following works fine in G++:
class myDefaultUClass{};
template <class T, class U = myDefaultUClass >
class myClass{
//...
};
Upvotes: 0
Reputation: 69792
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;
}
Upvotes: 0