Tried to compile following code, can't understand error message.
#include<iostream>
#include<string>
using namespace std;
struct S {
string a{"abc"};
const string& data() { return a; }
};
int main() {
S s;
int a = s.data(); // error: no viable conversion from 'const std::string' to 'int'
return 0;
}
Question: why does compiler say 'const std::string' instead of 'const std::string&'?
Tried with Apple clang 14.0.0 and g++ 12, same error message.