// B3 - assignment using explicit construction of temporary #include using namespace std; class X { public: X() : val(0) {} X(const X &x) : val(x.val) { } explicit X(int i) : val(i) { } X& operator=(const X& x) { if(this == &x) return *this; val = x.val; return *this; } operator const int () { return val; } private: int val; }; void main() { X x; //x = 5; // this won't compile since promotion constructor // has been qualified with the keyword explicit x = X(5); // this works because we are explicitly calling // the promotion constructor //x = (X)5; // Also works. cout << "\n value of x is " << x; cout << "\n\n"; }