Skip to content

Pass by value is bad practice. #3

Description

@bogdasar1985

I see many places in code, where objects pass by value, when could pass through ref(&).
For example:

// MapForCreating.cpp : line 3
MapForCreating::MapForCreating(string tilesPlace, string backgroundPlace, string playerPlaceIn, string platformPlaceIn)
{
    ...
}

All of this strings we can pass, by constant ref, like that const string& str.
The fact is that when passing by value, objects are copied, passing objects by reference, copying does not occur, therefore the program runs faster.
Also, look at pass by std::string_view, but in this case I am not an expert and not sure it can work for all four strings.
This may not only be about strings.

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