I have the following class as a wrapper around the basic type bool
:
class MyBoolean {
public:
MyBoolean(bool value = false):value(value) {};
virtual ~MyBoolean() {};
void MySpecialFunction();
...
private:
bool value;
}
I want to use MyBoolean
in expressions as normal bool
. That is, assign to it, compare, etc. For that I define the assignment and implicit type cast operators.
inline operator bool() const {
return value;
}
inline bool operator = (const bool &rhs) {
return value = rhs;
}
It seems however that the assignment operator is not needed. The following code compiles just with type cast operator, without the assignment operator:
MyBoolean b;
b = true;
Why doesn't the compiler complain it cannot assign bool
into MyBoolean
? What is the default implementation of the assignment operator from a different type in C++?