optimization - C++ Operator overloading styles, which is better for optimisation? -


there 2 ways overload binary operators in c++: member function, or non-member function.

since member function style can included in .h file, , non-member style in .cpp file, have thought member function style make easier compiler optimise.

  • is there difference in performance between member , non-member operators?
  • do member , non-member operators result in identical code (in compiler)?

the declaration member or not member has nothing optimization. compiler smart enough produce equally optimized code in both cases if changes. , anyway, low level optimization make sense precision compiler, version , configuration , can change one.

for question of readability , maintanability, operator should member... unless cannot. if can, allows declare inside class definition coherent oop: operates on objects of class, let's try make method on class.

simply there cases not possible. example, output streams injector (<< operator) can accept second operands of class, cannot defined member. that's reason why c++ allows non member definition of operators.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -