Hello everyone.
In C++, say I have two classes A and B. I can create a constructor A::A(const B&){...} or, if I cant modify the class A for some reason, I can define B::operator A()const{...}
Suppose I can't modify the class B either, but want to have a function used like this:
void foo (const A &);
B b;
foo(b);
If I had either of the two methods defined as above, this would be fine. Can I define a conversion operator, external to both classes, which will achieve the same thing?
In my mind this isn't very different to defining
A & operator = (A &, const B &);
so if what I'm asking is disallowed, can someone please explain the motivation?