S
Szabolcs
Consider the attached example. When I try to compile it (with g++
4.1.2), I get the error message
error: no matching function for call to 'fun(A<int>&)'
However, if I do not use templates, it compiles without errors.
Could someone please explain why this happens? Is there a workaround?
------------->8---------------
// With A and B templates
template<typename T>
struct B { };
template<typename T>
struct A {
operator B<T> () { return B<T>(); }
};
template<typename T>
void fun(B<T> b) { }
int main() {
A<int> a;
fun(a);
return 0;
}
------------->8---------------
// Without templates
struct B { };
struct A {
operator B() { return B(); }
};
void fun(B b) { }
int main() {
A a;
fun(a);
return 0;
}
4.1.2), I get the error message
error: no matching function for call to 'fun(A<int>&)'
However, if I do not use templates, it compiles without errors.
Could someone please explain why this happens? Is there a workaround?
------------->8---------------
// With A and B templates
template<typename T>
struct B { };
template<typename T>
struct A {
operator B<T> () { return B<T>(); }
};
template<typename T>
void fun(B<T> b) { }
int main() {
A<int> a;
fun(a);
return 0;
}
------------->8---------------
// Without templates
struct B { };
struct A {
operator B() { return B(); }
};
void fun(B b) { }
int main() {
A a;
fun(a);
return 0;
}