To const or not to const

The Const-correctness Principle

Why is it important ?

Examples in C++

class MyClass {
public:
MyClass(int value) : my_constant(value) {}
private:
const int my_constant{0};
static constexpr int my_other_constant{42};
};
const auto error_code = methodReturningAnError();
const auto& variable = methodReturningAnHugeElement();
auto myMethod (auto parameter) const;

Conclusion

Extra resources

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store