c++ Class Problem Questions

Asked 2 years ago, Updated 2 years ago, 137 views

The problem embodies the functions, constructors, and destructors of ClassInfo In the main() function, enter (B511001, Kim Cheol-soo, 23), (B611002, Kim Young-hee, 26), and (B411003, Youngsoo Kim, 24). Write down the students' information to be printed through stPrnt() constructor stInfo(string, string, int) in public; I have to write it declared What is the role of this constructor here? If you have a role, how do you send the information of three Youngsoo Kims, Kim Cheol-soo and Kim Young-hee, to this creator?

c++ class constructor

2022-09-22 20:57

1 Answers

Role of constructor: Method called when creating an object.

Object generation: stinfo_stinto = new stinfo("B511001", "Kim Cheol-soo", 23);

Stinfo ("B511001", "Kim Chul-soo", 23) is the code that calls the constructor.

Typically, the generator's role is used to initialize the class' global variable.

class stInfo {
private:
    string _schoolNo;
    string _name;
    int _age;
public:
    stInfo(string schoolNo, string name, int age);
    virtual ~stInfo();
};
...
stInfo::stInfo(string schoolNo, string name, int age) {
    _schoolNo = schoolNo;
    _name = name;
    _age = age;
}

That could be about it.


2022-09-22 20:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.