Specialising a member function with a template template parameter
Here is the guts of my problem...
I dont seem to be able to use the template template parameters TT1, TT2 & TT3 to specialize my member function Container:: object(). Basically I want to use them in order to select the
correct member variable index1_, index2_ and index3_ as this presents a nice Tag-style interface.
Any Ideas?
Code:
template<class T> struct X{ /* omitted*/ };
template<class T> struct Y{ /* omitted*/ };
template<class T> struct Z{ /* omitted*/ };
template < class T,
template <typename> class TT1,
template <typename> class TT2,
template <typename> class TT3>
struct Container
{
template <template <typename> class FTT> FTT<T> object();
/* All functions fail to compile. Error is
// error C3207: 'MyClass<T,TT1,TT2,TT3>:: object' :
// invalid template argument for 'FTT', class template expected
template <> TT1<T> object<TT1>() { return object1_;}
template <> TT2<T> object<TT12>() { return object2_;}
template <> TT3<T> object<TT13() { return object3_;}
//*/
//* Compiles but needs to use template template parameters for generality
template <> X<T> object<X>() { return object1_;}
template <> Y<T> object<Y>() { return object2_;}
template <> Z<T> object<Z>() { return object3_;}
//*/
private:
TT1<T> object1_;
TT2<T> object2_;
TT3<T> object3_;
};
int _tmain(int argc, _TCHAR* argv[])
{
Container<int, X, Y, Z> container;
X<int> result1 = container.object<X>();
Y<int> result2 = container.object<Y>();
Z<int> result3 = container.object<Z>();
return 0;
}