I have a static const std::vector<SomeType> field in my class. I have two private methods that uses this field (searching methods).
They do not use another members of my class. Should they be define as static or normal methods?
What should I prefer? What are advantages/disadvantages?
Methods that reference only static members should generally be defined static. This lets you access these methods without creating an instance of a class, and also access them from static context (e.g. from a non-member function).
The only exception to this rule is when you need to make this access from a member function defined virtual. In this case you have no option to make your function static, because static functions cannot override virtual functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With