struct A {};
struct B
{
B (A* pA) {}
B& operator = (A* pA) { return *this; }
};
template
struct Wrap
{
T *x;
operator T* () { return
This is because C++ Standard allows only one user-defined conversion. According to §12.3/4:
At most one user-defined conversion (constructor or conversion function) is implicitly applied to a single value.
B oB = a; // not tried: ob( a.operator T*() ), 1 conversion func+1 constructor
oB = a; // OK: oB.operator=( a.operator T*() ), 1 conversion func+1 operator=
As a workaround you can use explicit form of calling the constructor:
B oB( a ); // this requires only one implicit user-defined conversion