c++ - Why are operators sometimes stand-alone and sometimes class methods? -
Why sometimes an operator is defined as a method in the override class, such as
MyClass & amp; MyClass :: operatorFoo (MyClass and others) {.... back to this; };
And sometimes it is a separate function, such as
MyClass & amp; OperatorFu (Myclass and First, Myclass and Bar)
Are they equal? When you do it in one way and when you do it another, then what rules do you control?
If you want to be able to do something like 3 + obj
You have to define a free (non-member) operator.
If you want to make your operators safe or private, you can not
operate some operators, like, operator->
.
It has already been answered:
Comments
Post a Comment