A simple topic. Write it down for the purpose of memorizing it.
class A
{
A(int i); // implicit conversion: a --> A
public:
method1();
}
A a;
a = 1;
The compiler will implicitly transform the integer i to class A object a. Something like this happens under the hook:
A temp(1);
a = temp;
temp.A::~A();
Sometimes the implicit conversion is not desirable, and better turned off:
class String {
int size;
char *p;
//..
public:
//no implicit conversion
explicit String (int sz); //no implicit conversion
String (const char *s, int size n = 0); //implicit conv.
};
void f ()
{
String s(10);
s = 100; //now compile time error; explicit conversion required now:
s = String(100); //fine; explicit conversion
s = "st";//fine; implicit conversion allowed in this case
}