dimanche 30 août 2015

How fix compile error: invalid initialization of non-const reference of type 'std::__1::string&

I'm new in C++ and i can't figure out what's wrong with this code

 string& GetAddonCmeterString(string& sid) {
     ostringstream oss;
     oss <<  "{"; 
     oss <<     "currentValues : {sid : " << sid << "}"; 
     oss <<  "}";
     string& result = oss.str();
     return result;
 }

Compile error message:

error: invalid initialization of non-const reference of type 'std::__1::string& {aka std::__1::basic_string, std::__1::allocator >&}' from an rvalue of type 'std::__1::basic_string, std::__1::allocator >' string& result = oss.str();

Aucun commentaire:

Enregistrer un commentaire