First: when you have a constructor thst takes one argument, and this constructor is not marked as explicit, that means your type can be converted implicitly from that type. Example is line A a2 = i Second: operator Type() is conversion operator, if it's not marked explicit it means object of your class can be converted to Type implicitly. Example is line i = a1 More details here: https://en.cppreference.com/w/cpp/language/implicit_conversion and here https://en.cppreference.com/w/cpp/language/cast_operator The last two lines are explicit conversions, Note also that this code have some issues (apart from absence of explicit). The last two lines are using c-style casts that are not usually used in C++ (bad code style) and the constructor should set x in constructor intialization list instead of assigning it in the constructor body. Details: https://softwareengineering.stackexchange.com/questions/50442/c-style-casts-or-c-style-casts and https://en.cppreference.com/w/cpp/language/constructor
In the second line of main, I think you declare a variable called a2♒i
Обсуждают сегодня