You can pass objects to functions as arguments. Here, fnMainMenu
takes a reference to a constant std::string
object as parameter and prints it out to stdout:
void fnMainMenu(const std::string& msg)
{
std::cout << msg << "\n";
}
Then fnLogin()
can call the function and pass it any string it likes:
void fnLogin()
{
std::string s = "hello";
fnMainMenu(s); // call Main Menu and I want to pass "hello"
}
7
solved Passing value from one function to another [closed]