Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Methods that do not change the state of an object should be const. #7

Open
bogdasar1985 opened this issue Apr 4, 2021 · 0 comments

Comments

@bogdasar1985
Copy link
Contributor

Good example is a method virtual int getNumber() = 0; from class DynamicObject. It, moreover, should be made constant (like virtual int getNumber() const = 0;), because this method can be override in the descendant class. And if it is overridden in a way that changes the state of the object, it will break the semantics.

The same applies to the methods of the descendant class. For example int Player::getNumber(); should be
int Player::getNumber() const;.

@bogdasar1985 bogdasar1985 changed the title Methods that do not change the state of an object should be constant. Methods that do not change the state of an object should be const. Apr 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant