What can I do? Something had to not get inside my thick skull. The explicit keyword is the one. Just can't get it.
Why is that the following code is working. Why does it allow the implicit conversion?
This is the class:
and on main...Code:class Range { public: explicit Range(const int i): sInt_(i) { if(i < 0 || i > 255) throw std::out_of_range("Invalid small integer. Out of range."); } operator int() const { return sInt_; } private: size_t sInt_; };
Code:double i = 12; Range si(i);