C++ constness and reference
Case 1: Make function const vs. non-const const Track& ScoreTableElement::getTrackLeft() const { return left_; } vs. const Track& ScoreTableElement::getTrackLeft() { return left_; } The difference is, if the function is not marked const, then we can not call this function on a const variable or const reference variable, because this function could change the content of the object, so the const variable/reference will not allow the calling of this function. Example: sf::of::ScoreTableElement element(track_left, track_right, 4.5F); scoretable.push_back(element); const sf::of::ScoreTableElement element_out = scoretable.back(); // or const sf::of::ScoreTableElement & element_out = scoretable.back(); element_out.getTrackLeft(); // compiler error getTrackLeft() is not const function Case 2: Assign return const reference to const vs. non-const reference const Track& ScoreTableElement::getTrackLeft() const { ...