MyClass < int * >, MyClass < char * >, ...
and NOT:
MyClass < int > or MyClass < char > or ....
How can i do this? If i'm able to.
[edited by - schiggl on June 4, 2002 5:07:22 AM]
MyClass < int * >, MyClass < char * >, ...
and NOT:
MyClass < int > or MyClass < char > or ....
How can i do this? If i'm able to.
[edited by - schiggl on June 4, 2002 5:07:22 AM]
template<typename T> class MyClass;// No implementation for ''generic'' casetemplate<typename T> class MyClass<T*>{ // Implementation for pointer case};
#include <boost/type_traits.hpp>struct MyClassPointer// This struct holds the specialized implementation// for pointer types. // MyClassPointer has no template parameter because// we would need partial template specialisation...// and this is what we are trying to avoid.// Instead, it has a templated inner class.{ template<class T> class Implementation { public: void Foo() { // do something }; };};template<bool IsPtr> struct MyClassDispatch;// No implementation of the general casetemplate<> struct MyClassDispatch<true>// Redirect to MyClassPointer in the pointer case{ typedef MyClassPointer Type;};template<class T> class MyClass{public: inline void Foo() { typedef typename MyClassDispatch<boost::is_pointer<T>::value>::Type Type; // select a specialisation implementation Type::Implementation<T>::Foo(); // reapply the template parameter T and call the ''right'' Foo() };};