class counter
{ int amount;
public:
counter() { amount=0; }
counter operator++(?) //why does it have to be " counter operator++(int) "
//not " counter operator++(void) "
{ amount++; return *this; }
};
main()
{
counter a;
a++;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2002-10-17
so maybe anyone could tell me how to use ++ operator with friend and without friend function:
1) ++(something) using friend function
2) (something)++ using friend
3) ++(something) not using friend function
4) (something)++ -"-
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2002-10-17
i guess if i want to use ++(something) operator, i have to use friend function, and (something)++ can t be defined using friend function.
class counter
{ int amount;
public:
counter() { amount=0; }
counter operator++(?) //why does it have to be " counter operator++(int) "
//not " counter operator++(void) "
{ amount++; return *this; }
};
main()
{
counter a;
a++;
}
so maybe anyone could tell me how to use ++ operator with friend and without friend function:
1) ++(something) using friend function
2) (something)++ using friend
3) ++(something) not using friend function
4) (something)++ -"-
i guess if i want to use ++(something) operator, i have to use friend function, and (something)++ can t be defined using friend function.
my program:
#include <stdlib.h>
#include <iostream.h>
class counter
{ int amount;
public:
void show() { cout << amount << "\n\n"; }
counter() { amount=0; }
counter operator++(int) { amount++; return *this; }
friend counter operator++(counter& x) { x.amount++; return x; }
};
main()
{
counter object;
object++;
++object;
object.show();
system("pause");
}
am i right??