I am wondering the difference between these data types in C++:
const std::string&
std::string const&
for example: If I run this simple piece of code:
#include <iostream>
using namespace std;
int main()
{
std::string bar = "alpha";
const std::string &foo = bar;
std::string const &blah = bar;
std::cout<<"bar: "<<bar<<", foo: "<<foo<<", blah: "<<blah<<std::endl;
bar = "gamma";
std::cout<<"bar: "<<bar<<", foo: "<<foo<<", blah: "<<blah<<std::endl;
return 0;
}
I can observe all the values getting updated if I update the original string? Also is there a method to correctly read these data types, I heard of a right to left rule but not able to apply it?