Here is an example of what I'm trying to understand:
//no param function
std::string getPassword()
{
std::string password;
getline(std::cin, password);
return password;
}
//param function by ref
std::string getPassword(std::string& password)
{
getline(std::cin, password);
return password;
}
//void param function by ref
void getPassword(std::string& password)
{
getline(std::cin, password)
}
//in main
int main()
{
std::string password;
getPassword(password); //using void function
//OR
password = getPassword(); //using no param function
//OR
password = getPassword(password); //using param function
return 0;
}
Which one of these would be the best way to retrieve a password? Especially, if we're talking large scale like signing on to Netflix for example. I know this code is probably written differently in a professional environment but this is just a basic example to get my point across. I can't seem to find any post about this question so I thought I'd ask. I know the difference between returning by value/ref and returning void (it doesn't return a value) so no worries there.
***EDIT Is it an issue that the address of the string variable in main is different from the local one in the first function? (If you decide the first function is best that is)
Thank you to those that help!