Why does the following code give this error:
cannot bind non-const lvalue reference of type 'char&' to an rvalue of type 'char'
#include <string>
int main()
{
std::string p {"Test string"};
auto &r = p.data();
return 0;
}
The type of the pointer returned by std::string::data is char *. And the type of variable r is char *&. So why, in this case, the type of char * cannot be referenced by a type of char *?