-
February 4th, 2014, 06:19 PM
#1
operator overloading (prefix ++)
Hi...
I am writing the overloading operator function (prefix ++) according to my book.. but it doesnt work !!!!!!
But if i write:
void operator++()
{
++x;
}
it works !!!!!
Is the book wrong???
Here is my code according to the book that doesnt work as it should:
#include <iostream>
using namespace std;
class things
{
int x,y,z;
public:
void print()
{
cout<<x<<endl;
cout<<y<<endl;
cout<<z<<endl;
cout<<"*****"<<endl;
}
things():x(0),y(0),z(0){};
thing& operator ++() //******** here *******
{
++x;
return *this;
}
};
int main()
{
things table;
cout<<"*****"<<endl;
table.print();
++table;
table.print();
return 0;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|