Skip to content
New issue

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

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

Already on GitHub? # to your account

Pass by value is bad practice. #3

Open
bogdasar1985 opened this issue Mar 28, 2021 · 0 comments
Open

Pass by value is bad practice. #3

bogdasar1985 opened this issue Mar 28, 2021 · 0 comments

Comments

@bogdasar1985
Copy link
Contributor

bogdasar1985 commented Mar 28, 2021

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant