benben wrote:
I am looking for a good example of overloading operator , (operator comma)
Any suggestions?
Ben
You should not overload the comma operator unless you really have to
(Very good explained in Sutter, Alexandrescu: "C++ Coding Standards", I
will give a short summary):
The build-in comma operator gurantees that the expression before the
comma is evaluated before the expression after it:
typedef SOMETHING T;
....
T a = 42;
T b = ++a, ++a;
With T=int and the build-in comma operator this will assign 44 to b.
(The first (++a) expression is evaluated first, its result discarded,
and then the result of the second (++a) is returned)
If T is a user defined type and you have overloaded the comma operator
for this type, the order in which the arguments are evaluated, is
undefined, so the above example would be undefined - it could be 43 as
well es 44.
You should step back from overloading the comma operator, because you
cannot simulate the build-in behaviour.
Gabriel