What's the difference between doing this:
class_name object_name = something;
and
class_name object_name(something);
From what I read here, both use the copy constructor but I don't understand why that happens and how implicit conversions come into play. How I understood it (before reading about it) was that the first uses the default assignment operator (if not defined) by creating a temp object and then calls the copy constructor but that seems to be wrong. I am asking because I read that when making the copy constructor explicit, the first option will fail even if something is of class_name type, so the two options must be different enough. Also is the assignment operator used (using default or user-defined implementation) on top of the copy constructor in the 1st option or is it just a user-friendly syntax form of calling the copy constructor?
If the copy constructor is explicit, the first form could only be achieved by writing:
i.e. explicitly calling the copy constructor.
In the end, though, if the copy constructor is explicit, just use the first form if this is unambiguous (beware the most vexing parse), or for extra c++11 points use the brace initialiser syntax, which can never be ambiguous:
OR using Herb Sutter's "almost always auto" idea:
To answer your other question, the assignment or copy-assignment operators are not used here. The copy-assignment operator is used where you are assigning a copy to a previously initialised variable: