uray
uray

Reputation: 11562

partial function template specialization with templated object as function argument

suppose i have this class :

template <typename T> class MyClass{
}

template <typename T> class MyOtherClass{
}

and some generic template function

template <typename A> void someFuncT(const A& arg){ //generic function template
    //... body here
}

I want to specialize A for MyClass<T>, but doing this, will be error

template<> template <typename T> void someFuncT(const MyClass<T>& arg){ //specialized for A = MyClass<T>
    //... body here
}

on the other side, doing this is okay

template <typename T> void someFuncT(const MyClass<T>& arg){
    //... body here
}

template <typename T> void someFuncT(const MyOtherClass<T>& arg){
    //... body here
}

but it will be ambiguous for :

MyOtherClass other;
someFuncT<MyOtherClass>(other);

which could create :

void someFuncT(const MyClass<MyOtherClass>& arg){ }

but the intention is to create a specialized template for A = MyOtherClass, so :

void someFuncT(const MyOtherClass& arg){}

so how to do function template specialization if one of the arguments of the function is a class with another template ?

Upvotes: 0

Views: 40

Answers (0)

Related Questions