0

I have a class called Person with no default constructor :

class Person{
public:
    Person(std::string name); 
}

and a class usingPerson within which I want an object person as an attribute:

class usingPerson{
public:
    someMethod();


private:
    Person p1;

this gives me the error : class person has no default constructor.

I know this seems basic but I'm new to programming so can you tell me how do I initialise it with a name.

  • Note that the access specifier such as `private` is irrelevant to this error. – cigien Nov 27 '20 at 17:17
  • 1
    Ah. The member initializer list. The ratio of its importance to the language to the frequency with which it is taught is almost infinity. – user4581301 Nov 27 '20 at 17:18
  • You'll need to initialize it in the constructor or inline, with the name that it should be initialized with. – Eljay Nov 27 '20 at 17:25

0 Answers0