Why isn't the argument passed by value ?
When I tried it, my compiler just gave me a message saying "you probably meant Foo(const Foo&)
."
What is the reason for this ?
Why isn't the argument passed by value ?
When I tried it, my compiler just gave me a message saying "you probably meant Foo(const Foo&)
."
What is the reason for this ?
Because pass by value requires a copy constructor in the first place.
So to avoid infinite recursion, the pass by reference copy constructor has to be defined before the pass by value version if we really want to have a pass by value one. As it does not make much sense to have a pass by value copy constructor, the standard forbids it.
You are simply not allowed to pass it by value - §12.8 [class.copy]/p6 of the standard explicitly prohibits it :
A declaration of a constructor for a class
X
is ill-formed if its first parameter is of type (optionally cv-qualified)X
and either there are no other parameters or else all other parameters have default arguments. A member function template is never instantiated to produce such a constructor signature.
The reason for this prohibition, as explained in the comments, is infinite recursion - "to make a copy, you have to make a copy" doesn't make much sense.