I’d like to specify a conversion from A<T>::B to A<U>::B.
template<typename T>
struct A
{
struct B
{
B() {}
template<typename U>
B(const typename A<U>::B& rhs) {}
};
};
int main()
{
A<int>::B x;
A<double>::B y = x;
}
I thought this would do it, but I get the compiler error:
conversion from ‘A<int>::B’ to non-scalar type ‘A<double>::B’ requested”
Why isn’t my code correct, and what’s the correct way to achieve the desired conversion?
Slightly amended source, to demonstrate that this is about the limits to the type deduction system:
You see that when we help the compiler a little, there is no more problem. Also note the actual compiler error (gcc) shows it’s confusion:
Notice the part where
U = U(i.e. unresolved)