I am using a template function that is defined like this (using a trait concept):
The default trait looks like this:
Normally if you want to change the behaviour here for a certain type you do a specialization like this:
My problem is that I want to define a class like this:
and then create a trait for that class so that I can use the function f with an object of type C as parameter. Does anyone know how I can do this?
- Code:
template <class T>
f(T t)
{
f_trait::DoSomething(t);
..
}
The default trait looks like this:
- Code:
template <class T>
class f_trait
{
void DoSomething(T t) {blah();}
};
Normally if you want to change the behaviour here for a certain type you do a specialization like this:
- Code:
template <>
class f_trait
{
void DoSomething(int t) {DoSomethingElse();}
};
My problem is that I want to define a class like this:
- Code:
template <class T>
class C
{
void SomeOtherStuff();
};
and then create a trait for that class so that I can use the function f with an object of type C as parameter. Does anyone know how I can do this?