c++ - prefix operator overloading -


I overload the ++ prefix operator using a member function. Here's the prototype:

  test and operator ++ ();   

But my suspicions arise when I use it for my object below:

  test t; ++ t;   

As far as I know that the operator is exaggerated by the any operator for on the left but when that operator I'm calling this ++ prefix overloaded operator, so I do not need any object in class test on the left.

Why?

So far I have learned that for any operators overloaded by any member operator The object of the same category on the left side of that operator should be one.

This will be pre-and post-indentment for any binary operator, as well as a direct operator ( * obj ) operators Are there. They have an argument (either a function parameter or contained "this" parameter, how you overload the operator) and for overloaded operators it should be only one class type.

But when I am calling this ++ prefix surcharge operator, then I do not need any of the test class on the left side.

Unir operators have "left" and "not correct" side (operand), they only have one operand.


Remember in your case:

  ++ t;   

means only:

  T. Operator ++ ();   

So - in some twisted thinking - t is actually on the left :)

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -