Can you 'create' new operators? Like a +++ which would, for example add two to the variable? I tried making a simple program to find the answer for myself. But I failed miserably; I don't know if it's because I'm overlooking something, or you simply cannot do what I'm asking.
I got numerous errors in this code. I'm not asking for it to be debugged, I would just like to know if I'm implementing the overload of operators properly.Code:#include <iostream.h> typedef unsigned short int USHORT; class addthis { public: addthis() { val = 0; } ~addthis() {} addthis(USHORT x) { setVal(x); } USHORT getVal() { return val; } void setVal(USHORT x) { val = x; } addthis operator+++ (); addthis operator++ (); private: USHORT val; } addthis addthis::operator+++() { val = val+2; } addthis addthis::operator++() { val = ++val; } int main(void) { addthis ADDTHIS(22); cout << ADDTHIS.getVal(); ADDTHIS+++; cout << ADDTHIS.getVal(); ADDTHIS++; cout << ADDTHIS.getVal(); ADDTHIS.flush(); cout << "ADDTHIS.getVal(); SYSTEM("PAUSE"); return 0; }



LinkBack URL
About LinkBacks


