rvalue and lvalue of std::string

239 Views Asked by At

i ran the code as shown and i am confused as to why a+b is a rvalue. From what i know, rvalue should only have a data or address and in such a case std::string should be a lvalue isn't it?


void foo(const std::string&& input){
    std::cout<<"RVALUE "<<input<<std::endl;
}
void foo(const std::string& input){
    std::cout<<"LVALUE "<<input<<std::endl;
}

int main(){
    std::string a = "Tom";
    std::string b = "Cruise"; 
    std::string c = a + b;
    foo(a+b);
    foo(c);
}

OUTPUT

 RVALUE TomCruise 
 LVALUE TomCruise
0

There are 0 best solutions below