defaul value class for template

I wonder if I can make a template with a default value for a class of mine, as follow:
1
2
3
4
5
6
7
8
9
class MyClass
{
  ....
}
template<class T = MyClass>
class  ClassTemplate
{
   ....
}

because I have tried and only works with its own language settings
1
2
3
4
5
template<class T = int >
class ClassTemplate
{
   ...
}
You can do it for every types as long as they can be used as a regular argument.
I would say here that MyClass is not a valid type to use as a parameter of ClassTemplate, it may be an operator or conversion not supported because it works with int. See what operation you use on type T and check if MyClass have them or not.
What have you tried and how did it fail? The code you posted works (once the missing semicolons are added):

1
2
3
4
5
6
7
8
9
10
11
class MyClass
{
};
template<class T = MyClass>
class  ClassTemplate
{
};
int main()
{
    ClassTemplate<> ct;
}
what is your full code .. i would like it to try ..
Topic archived. No new replies allowed.