Considering the following small code snippet:
template <typename T>
class A{
public:
A() { };
~A() { };
// ...
template <typename outT = T> operator std::vector<outT>(){ /* implicit/explicit cast to std::vector */ }
};
template <typename T = float>
void myFunc(const std::vector<T>& _arg){
printf("myFunc\n");
}
int main(int argc, char const *argv[]) {
A<int> foo;
myFunc(foo);
}
When trying to compile, I get the error
template argument deduction/substitution failed: [...] ‘A<int>’ is not derived from ‘const std::vector<T>’
While, on the other hand, if myFunc
is not a template, it will compile and run just fine. I assume the error is caused by the fact that since myFunc
accepts multiple vector types as argument, the compiler does not know to what type it should convert foo
to. However, shouldn't the default template values be used as fallback in such case? Is there an alternative way to be able to pass an object of class A
to myFunc
?