In C++, if a class has a constructor which can be called with a single argument, then this constructor becomes conversion constructor because such a constructor allows automatic conversion to the class being constructed.
The above program prints:
x = 20
x = 30
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Copy constructor vs assignment operator in C++
- When is copy constructor called?
- When should we write our own copy constructor?
- Does C++ compiler create default constructor when we write our own?
- C++ default constructor | Built-in types
- Advanced C++ | Conversion Operators
- Advanced C++ | Virtual Constructor
- Advanced C++ | Virtual Copy Constructor
- Catch block and type conversion in C++
- Why copy constructor argument should be const in C++?
- Is it possible to call constructor and destructor explicitly?
- Conversion of Struct data type to Hex String and vice versa
- __attribute__((constructor)) and __attribute__((destructor)) syntaxes in C
- Copy Constructor in C++
- Order of Constructor/ Destructor Call in C++