When passing std::string is passed, object is copied through a stack.


void loadFromFile(std::string fileName);


So, parameter is passed in reference type to prevent object copy load in the stack.


void loadFromFile(std::string& fileName);


But, if the argument is in default argument format, compile error occurs.

 

void loadFromFile(std::string& fileName = ""); // compile error


If you would like to use string as default argument, the following code is preferable.


const static std::string NULL_STR = "";

void foo_str(const std::string& fileName = NULL_STR)


:)