How to define one side operators like ++
or --
in c++?
for example we want to define a##
to do (a % 45) + 2
[It is just an example]
How to define one side operators like ++
or --
in c++?
for example we want to define a##
to do (a % 45) + 2
[It is just an example]
There is operator ++()
(prefix increment operator)
and operator ++(int)
(postfix increment operator)
Same for operator --
.
class Example
{
public:
int a = 0;
Example& operator++() { a = (a % 45) + 2; return *this; } // ++ex;
Exampleoperator++(int) { Example tmp = *this; ++(*this); return tmp; } // ex++;
};
There is no operator ##
.