[wx-dev] Why are the operators(+, -, * ,/) members?

Vadim Zeitlin vadim at wxwindows.org
Wed Nov 1 12:50:37 PST 2006


On Wed, 1 Nov 2006 19:19:19 +0100 Bernd Donner <Bernd.Donner at gmx.net> wrote:

BD> I'm just wondering if there is a specific reason why
BD> operators(+,-,*,/) are members of wxSize.

 No specific reason, they could be global functions.

BD> wxSize operator*(const wxSize& sz, int i) {
BD>   wxSize ret(sz);
BD>   ret *= i;
BD>   return ret;
BD> }
BD> 
BD> This has two advantages compared to the current implementation:
BD> 
BD> 1.) operator* is implemented in terms of operator*=

 Notice that this is not always appropriate. Even in this case one could
ask if implementing operator*= in terms of operator* wouldn't be better.

BD> 2.) We could also provide wxSize operator*(int i, const wxSize& sz).
BD> This is a great advantage, I think.

 Yes, it's not very consistent to be able to write sz*2 but not 2*sz, I
agree.

BD> The above function operates on wxSize and on wxPoint. Putting it in
BD> wxPoint is somewhat arbitrary.

 Yes.

BD> If there are no objections to this suggestion, I am willing to write a
BD> patch for gdicmn.h and gdicmn.cpp with the proposed changes.

 I don't see any urgent need to do this change on its own as we don't gain
much from it but if you want to add the other operators then it would
indeed make sense and would be welcome.

 Thanks,
VZ





More information about the wx-dev mailing list