-11

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
?
sdubs177
  • 11
  • 4

2 Answers2

3

There are 4 or 5 constructors in person.
The 3 you defined yourself, plus the compiler-generated copy constructor.

If C++11 is used, specific rules determine whether or not a move constructor will be generated for you, see here and here.

Community
  • 1
  • 1
Beta Carotin
  • 1,659
  • 1
  • 10
  • 27
  • move constructor and move assignment are not automatically generated. – NathanOliver Jul 10 '15 at 20:21
  • 1
    @NathanOliver Move constructors are automatically generated (under the right conditions) [Conditions for automatic generation of default ctor, copy ctor, and default assignment operator?](http://stackoverflow.com/questions/4943958/conditions-for-automatic-generation-of-default-ctor-copy-ctor-and-default-assi). The C++0x section states the conditions. – James Adkison Jul 10 '15 at 20:26
0

I counted five constructors because I have 5 fingers on my hand.:) However among possible answers

1
2
3
7

there is no answer with the number 5. So I am thinking whether it is only me who has 5 fingers on the hand or others can not count up to 5.:)

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335