Assuming you have C ++ in mind, it is always better to define functions outside the class, because if you put it inside the class, the compiler may try to embed it, which is not always desirable:
- Increasing code size (each object file that includes this header may end up with a copy of the function in their code).
- Violation of binary compatibility when changing the definition of a function.
Even with built-in functions, it is usually better to set definitions outside the class to improve readability of the classβs open interface, unless the function is a trivial accessory or some other single-line interface.
source share