1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
class MyClass {
public:
MyClass(int x) {
std::cout << "Constructor called with " << x << std::endl;
}
};
void printMyClass(const MyClass& obj) {
std::cout << "In printMyClass function" << std::endl;
}
int main() {
MyClass obj = 42; // Implicit conversion from int to MyClass. Use 42 as arg to the constructor.
MyClass obj1 = 52; // Implicit conversion from int to MyClass
printMyClass(100); // Implicit conversion and then passing to function
return 0;
}
Back to explicit