What’s the difference between the following two declarations, assuming I have not specified a copy constructor and operator= in class Beatle?
Beatle john(paul);
and
Beatle john = paul;
Edit:
In objects assignment, the operator = implicitly calls the copy constructor unless told otherwise?
They’re different grammatical constructions. The first one is direct initialization, the second is copy initialization. They behave virtually identically, only that the second requires a non-
explicitconstructor.*Neither has anything to do with the assignment operator, as both lines are initializations.
To wit:
const int i = 4;is fine, butconst int i; i = 4;is not.*) More accurately: The second version does not work if the relevant constructor is declared
explicit. More generally, thus, direct-initialization affords you one “free” conversion:To address your edit: To understand the assignment operator, just break it up into parts. Suppose
Foohas the obviousoperator=(const Foo & rhs). We can sayx = y;, which just calls the operator directly withrhsbeingy. Now consider this: