Working in VC++ and here's my problem, was reading through my "SAMS Teach yourself C++ in 1 hour a day" and got to chapter 13 which is supposed to teach operator overloading, but when I modified the code from the book, as such:
it gives me the errors:Code:#include <iostream> using namespace std; class number //class to test the reprogramming of the "++" increment operator { public: number(); ~number(); int mynumber; void inc(int increment) // replacement function for ++ operator { mynumber += increment; } number& operator ++ () // reprogramming the ++ operator { inc(1); return *this; } void dmn() // dmn = display mynumber { cout << mynumber; } void setnum(int x)// sets mynumber value { mynumber = x; } }; int main() { int z; cout << "Please choose start point : "; cin >> z; number newnumb(); newnumb.setnum(z); newnumb.dmn(); ++ newnumb; newnumb.dmn(); system("PAUSE"); return 0; }
1. error C2228: left of '.setnum' must have class/struct/union
2. error C2228: left of '.dmn' must have class/struct/union
3. error C2171: '++' : illegal on operands of type 'number (__cdecl *)(void)'
4. error C2105: '++' needs l-value
5. warning C4550: expression evaluates to a function which is missing an argument list
6. error C2228: left of '.dmn' must have class/struct/union
1, 2, and 6 annoy me, because I don't understand why it's printing it
3 and 4, I am just clueless as to what they mean...



LinkBack URL
About LinkBacks


