Kilomeliver
Class a {
PUBLIC:
A (INT I): M_i (i) {}
INT M_I;
}
Int main () {
A a = 0;
A = 10;
}
Tell you separately:
1. a a = 0;
First, Compiler believes that this is not in line with the rules, because A = a is normal behavior.
But she does not give up, through search, found A can be constructed according to an int structure, and this A (INT i) is not modified with ExPlicit.
So A a = 0; this sentence is then transformed into:
A TMP (0);
A a = TMP;
It should be noted that a a = TMP is called Copy CTOR, although there is no Class A, but usually does not write a Copy Ctor,
COMPILER will generate a CTOR of a MEMBERWISE ASSIGNMENT operating nature, and the underlying implementation is usually made in Memcpy.
2. a = 10;
First, like this to the CTOR, Compiler cannot operate directly.
Category push, equivalent to code:
A TMP (10);
a = TMP;
It should be noted that A = TMP is called Assignment operation, like CTOR, we don't write, the compiler is also
MEMBERWISE ASSIGNMENT operation.
3. Fn (a a)
Similarly, Fn (10) is not right, but "according to the practice", huh, it will be:
A TMP (10);
Fn (TMP);
In addition, for you:
Copy CTOR will only be T :: T (Const T &);
The ASSIGNMENT's way of writing can be changeable, let alone. T as T,
You may have
T & Operator = (int N);
Can also
T & Operator = (const char *);
Of course, you have to confirm that this is the meaning of T.
Then, the above A = TMP, that is, the default, standard, automatically generated T & Operator = (Const T &).
The overhead will have a temporary A TMP generation, then Memcpy.
But if you have written T & Operator = (int N), then A = 10 means A.M_I = 10.
Of course, in terms of overhead, regard your T & Operator = (int N) is inline.
For ExPlicit, when modified Explicit A (INT I): M_i (i) {}, then telling Compiler not to do so many conversion actions in private.
And what is automatically generated such as A TMP (0) is what we don't want, because in some cases, this behavior is wrong.
Finally, there is a topic of this problem, that is, Class A can have Operator Int (), will
Fn (int N) {}
A a (3);
Fn (a)
Get a magic role. About this, leave you yourself to see the book :)
Finally, I wish to learn C on the way. Good luck ~