I am a newbie with this topic in cpp and trying to usnderstand through this code, so please tell me how l-values and r-values make difference in this code and how they are implemented. Also why am i getting error here (do execution of this code depends on c++ version)?
void printName(const std::string& name){
std::cout << "[l-value] " << name << std::endl;
}
void printName(std::string&& name){ //Line 8
std::cout << "[r-value] " << name << std::endl; //Line 9
}
int main(){
std::string firstname = "Harry";
std::string lastname = "Singh";
std::string fullname = firstname + lastname;
printName(firstname);
printName(lastname);
printName(firstname+lastname);
}
I am getting following mentioned error on the following code.
8 error: expected ',' or '...' before '&&' token
9 error: 'name' was not declared in this scope