How many constructors are in the person class above?

Consider the implementation of the following class

class person {
private:
int age;
int getAge();
void setName(string);
public:
string name;
person(int , string);
person(string);
person();
void setAge(int);
string getName();
}

How many constructors are in the person class above?
1
2
3
7
Five actually. (Or four in C++03).
How many constructors are in the person class above?

Yeah, Five but your instructor will want you to say 3 because only 3 are explicitly defined.
The other 2 (copy constructor and move constructor) are created by the compiler as long as there is no definition of a
- copy ctor
- move ctor
- copy-assignment operator
- move-assignment operator
- destructor

Since none of those are defined in your class the copy ctor and the move ctor will be implicitly created by the compiler.

Move ctor and move assignment operator were added in C++11. before that they just fall out of that list.
Last edited on
Registered users can post here. Sign in or register to post.