+ 1

help me c++ class

i need to understand this..help me class Example{ public : int x; Example(int y){x = y;} } then in main method,what does this two means? Example a(3); Example b = 3; i see that example b worked.. why there is no error,cause i want to assign b( Example type) to an int..? are a and b same?

4th Apr 2020, 7:00 PM
durian
durian - avatar
2 ответов
+ 3
The compiler can use non-explicit constructors as converting constructors, which specify an implicit conversion from the types of their arguments (a single integer in this case) to the class type (Example in this case). Those constructors are not only considered during direct initialization, such as Example a, but also in copy initialization, like with Example b. More on the explicit keyword: https://en.cppreference.com/w/cpp/language/explicit
4th Apr 2020, 7:23 PM
Shadow
Shadow - avatar
0
ok..i got it now.tq so much
5th Apr 2020, 3:52 AM
durian
durian - avatar