in the below code (which is an example for type conversion):
// implicit conversion of classes:
#include <iostream>
using namespace std;
class A {};
class B {
public:
// conversion from A (constructor):
B (const A& x) {}
// conversion from A (assignment):
B& operator= (const A& x) {return *this;}
// conversion to A (type-cast operator)
operator A() {return A();}
};
int main ()
{
A foo;
B bar = foo; // calls constructor
bar = foo; // calls assignment
foo = bar; // calls type-cast operator
return 0;
}
in line 21:
bar = foo; // calls assignment
it calls the overloaded operator =. and in the body of class overloading for "=" operator is written in line 12:
B& operator= (const A& x) {return *this;}
it's statement says "return this". here this points to bar. and there's just a parameter of type class A:
const A& x
what does this function do with this parameter?
and in line 21 what is converted to what by writing:
bar = foo;
?