Home c++ class designer. I do not understand. C++

class designer. I do not understand. C++




Good day!

I study the book of dealers, 5 edition. And here or the translator leaving or I can not understand – where are the essence.
On page 162, the designer definitions. I bring a heavy text for remembrance:

  1. for a class that does not define the designer, the default designer is implicitly created by the compiler. Such a designer ne.
    Initializes class data elements, however causes a constructor
    Default for each element that is the object of another

I can not understand: the designer created implicitly compiler does not provide the elements of the class …
And what side does it cause another class designer? What kind of “other”, if we are talking
About one particular? I can not grab the essence of the chain …

  1. The Compiler Implicitly Creates A Default Constructor in a class That Does Not Define A Construction. SUCH A DEFAULT CONSTRUCTOR DOES
    NOT INITIALIZE THE CLASS’S DATA Members, But Does Call The Default
    Constructor for Each Data Member That IS An Object Of Another Class.

Like the translation is quite correct. That is, the compiler sees that in the class of Fistclass
Not specified is clearly the constructor and the compiler creates an implicit designer. It’s clear.
And what are there any other classes? How can this constructor call a constructor of another SecondClass (for example)? Why are they talking about them? What does this paragraph want to tell me?

Answer 1, Authority 100%

Most likely the authors of the book tried to be more or less pedantically correct and wanted to take into account the fact that constructors in C++ are only at class-types. The non-class of types of designers does not have and cannot be determined. That is, like int , for example, no designer.

is exactly the most likely to understand this phrase. That is, the fields are not class-types are not initialized in any way, but for fields that are objects of classes (others, of course), constructors are caused.

For this class

struct s
 int i;
 STD :: String S;

The compiler implicitly generates the default designer S :: S () . This constructor will not initialize the I field, but will call the default designer for the s field (this is, according to the book, “Data Member That Is An Object Of Another Class”) .

phrase, of course, is formulated by cryption.

Modern language standard describes behavior in such cases as follows:

  • If the user has not yet announced any designers for a class, the compiler will implicitly announce and determine the default designer for this class . Such an implicitly defined default designer will perform default initialization of all sublises (fields and bases) of the class.

    • For clarity types default initialization means calling their default designers.
    • For sublises of type “Array” Default Initialization means the default initialization of the elements of the array.
    • For the owners of other types default initialization means no initialization at all.

    & nbsp;

    – with the exception of cases where the default designer is implicitly determined: the presence in the field of fields type “link”, the presence of class-type lords without a default designer and with an inaccessible default designer , the presence of constant type fields without the initializer and without a default designer user, etc.

Answer 2

I was answered by an example on CyberForum. When I started the code, I began to understand the logic in what.
I hope that someone will also help.

# include & lt; iostream & gt;
Using Namespace STD;
Class A.
  A ()
    COUT & LT; & LT; "Class A" & lt; & lt; Endl;
Class B.
  A A;
  B b;
  Return 0;

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions