C++ examples for Class:Operator Overload
Conversion Operators: a constructor that takes an int and produces a Counter object.
#include <iostream> class Counter /*www . j a v a2s. c om*/ { public: Counter(); ~Counter() {} Counter(int newValue); int getValue() const { return value; } void setValue(int newValue) { value = newValue; } private: int value; }; Counter::Counter(): value(0) {} Counter::Counter(int newValue): value(newValue) {} int main() { int beta = 5; Counter alpha = beta; std::cout << "alpha: " << alpha.getValue() << std::endl; return 0; }