This question might overlap with this one: C++ explicit template specialization of templated constructor of templated class . However, I didn't find a solution in that thread.
I have a templated class with templated constructor:
template<typename First, typename ... Rest> class var {
public:
template<typename T> var(T& t) {
std::cout << "general" << std::endl;
}
};
But in case this class is instantiated with an object of the same class as parameter (i.e., we'd like to call the copy- (or move-) constructor) something specific should be done. So I tried the following:
template<typename First, typename ... Rest> template<>
var<First, Rest...>::var(var<First, Rest...>& v) {
std::cout << "copy" << std::endl;
}
When trying to compile this with g++ 4.6 I get error: invalid explicit specialization before ‘>’ token error: enclosing class templates are not explicitly specialized confused by earlier errors, bailing out
I see the problem, I would have to say explicitly for which class I would like to specialize the constructor...
However, I hope it became clear what I want to do. Any ideas how?