Consistency in placing operator functions

Posted by wrongusername on Stack Overflow See other posts from Stack Overflow or by wrongusername
Published on 2010-06-14T06:33:06Z Indexed on 2010/06/14 7:12 UTC
Read the original article Hit count: 187

Filed under:
|
|
|

I have a class like this:

class A {
    ...private functions, variables, etc...
public:
    ...some public functions and variables...

    A operator * (double);
    A operator / (double);
    A operator * (A);
    ...and lots of other operators
}

However, I want to also be able to do stuff like 2 * A instead of only being allowed to do A * 2, and so I would need functions like these outside of the class:

A operator * (double, A);
A operator / (double, A);
...etc...

Should I put all these operators outside of the class for consistency, or should I keep half inside and half outside?

© Stack Overflow or respective owner

Related posts about c++

Related posts about class