I'm trying to implement an operator overload for a class such as:
template<class T> class A{
public:
T val;
A<T>& operator=(const T& v) {
this->val = v;
return *this;
}
}
So I can do:
A<bool> obj;
obj = true; // instead of obj.val = true
obj = false;
This works fine.
However, if I do this:
A<bool> obj;
obj = 123123; // bool is not a number!
It still works! Can I somehow prevent that?
I tried marking the overload explicit
like this:
explicit A<T>& operator=(const T& v) { ... }
but I get an error:
error C2071: 'A<T>::operator =': illegal storage class
Is it even possible to do this?