About the constructor of the c++

Asked 2 years ago, Updated 2 years ago, 24 views

Hello. Thank you for your hard work.

While looking at the explicit keyword

I'm asking you a question while I was testing it alone.

Code is

class MyClass { public: MyClass(){} MyClass(int num) : imember2(num){} MyClass(char cnum) : cmember(cnum){} MyClass(double dnum) : dmember(dnum){}

private: int imember; int imember2; double dmember; char cmember;

};

void main() { MyClasstemp = 10; // Possible (implicit the creator) Same as MyClasstemp (10)

MyClasstest(); //Call default constructor

test = 20; // Some variables in the class are initialized using the constructor of the defined datatype test = 'z'; // Same as above test = 4568.21; //Same as above

}

It's after creating the object Why do I ride the constructor that fits the type defined on the object?

Since it's already been created, the copy generator doesn't seem to automatically appear as many constructors.

Is the college admissions operator overloaded? I googled it and explained it only when I put an object in the object

It doesn't say that only the member variable of the object is included, so I'm asking you a question ㅠ.ㅠ.

Thank you for reading this long article. You'll be blessed.

c++

2022-09-22 20:55

1 Answers

After you create the object, the constructor is not called. The above code is not compiled.


2022-09-22 20:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.