3 ms·
Static also allows the compiler to make better optimizations, knowing that nothing outside of the current compilation unit will ever use it. Const also allows
by kstenerud 12y ago
Static also allows the compiler to make better optimizations, knowing that nothing outside of the current compilation unit will ever use it.
Const also allows the compiler to optimize better with the knowledge that the called function won't perform any writes to the object state.
Access modifiers give you a way to separate out functions that can be called externally vs those that shouldn't. The API doc generator won't know which is which unless you mark these correctly. You use access modifiers to show intended use and keep things clean, not to lock someone out. Same goes for internal classes.
- plorkyeran 12y agoIn practice const very rarely allows any interesting compiler optimizations (passing a reference to a const local variable to a function whose body cannot be seen is pretty much the only place where it's safe to do so). The const overload of a function with const and non-const versions could in theory be faster, but copy-on-write data structures are the only common example of that actually being the case.