Reputation: 138
I have a question regarding Copy constructors.
A constructor defined as below, do we call it a copy constructor or just an overloaded constructor ?
A(const A& obj,int x, char y='A')
Upvotes: 2
Views: 1364
Reputation: 254771
Copy constructors are defined thusly:
C++11 12.8/2: A non-template constructor for class
X
is a copy constructor if its first parameter is of typeX&
,const X&
,volatile X&
orconst volatile X&
, and either there are no other parameters or else all other parameters have default arguments
In other words, it must be callable with a single argument - a reference to the object to be copied - but can have extra, optional, parameters.
Your example doesn't meet this requirement since it has two mandatory parameters. If the second parameter had a default value:
A(const A& obj, int x=42, char y='A')
then it would be a copy constructor.
Upvotes: 7