Literally, the question is "Define the constructor for class Z". Help me figure out what exactly needs to be implemented? Well, the type constructor of the class Z already has something missing? It is important for me to understand what is required and how to implement it so that in the future I myself could solve such problems.

class A { public: A ( int a ) { aa_ = a; } private: int aa_; }; class Z { public: Z(); private: const int & r_; const int i_; A a_; }; 
  • I understand that the task is to write the definition of the constructor, that is, write the code for it. That he initialized the variables for example - Mark Starikov
  • one
    "Define" means "define." You have no definition for constructor for Z yet. So far you only have an ad . - AnT

1 answer 1

When creating any constructor in a class, other constructors by default are not created if a constructor A is created in class A (int a), then the default constructor and the copy constructor are no longer automatically created.

 class A { public: A ( int a ) { aa_ = a; } private: int aa_; }; class Z { public: Z(int a, int r, int i) : r_(r), i_(i), a_(a) {} private: const int & r_; const int i_; A a_; }; 
  • 2
    About the copy constructor is incorrect. The copy constructor is always declared. You can suppress the implicit declaration of the copy constructor only by explicitly declaring your copy constructor. Also in this class the displacement constructor will be implicitly declared. What happens to the definitions of these constructors is a separate story, but they will be announced. - AnT