D
D
Daniil Romanov2020-04-27 12:30:40
C++ / C#
Daniil Romanov, 2020-04-27 12:30:40

What does this constructor do?

I am taking a course on Stepik on the pluses, I had difficulties in understanding one moment in the task.

Part of the condition from the problem:
The following class is defined (it is also commented in the code template):

struct Cls {
    Cls(char c, double d, int i);
private:
    char c;
    double d;
    int i;
};


What the constructor does It does not set the values ​​of the fields, but the arguments are passed to it. Cls(char c, double d, int i);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Zhilin, 2020-04-27
@chattydude1

This is a constructor declaration. Field values ​​must be specified in the definition. Since there is no definition here, it means that it must be looked for somewhere else. You may find it in one of the next steps. Perhaps its writing is left as an exercise for the reader. Perhaps the content of the constructor (assigning parameters to fields) was considered obvious by the authors.
An example of a definition that should follow such a class:

Cls::Cls(char c, double d, int i)
    : c(c), d(d), i(i) {}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question