lundi 16 décembre 2019

The return string alias can be 'seen' with the defined name in caller scope without as global

How to have the return string alias can be 'seen' with the defined name in caller scope, without being as global nor passing it off ? illustration is sort of:

using namespace std;
string& first(string& s);

int main(){
  string m("Hello");
  string return_str, result;

  result = first(m); // or
                          //cout << first(m);
}


string& first(string& s){

    return_str=s + "World";
    return  return_str;

}

How to solve such by making use of best c++ features ?

Aucun commentaire:

Enregistrer un commentaire