Skip to content

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

@bogdasar1985

Description

@bogdasar1985

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;.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions