I found the below link which said "lvalue and rvalue reference interface can combine in one". Pass lvalue to rvalue
but when I take it for example. compile error appeared cannot bind ‘std::string {aka std::basic_string}’ lvalue to ‘std::string&& {aka std::basic_string&&}’
. Below is my implementation.
#include <iostream>
#include <string>
using namespace std;
void g(string &&b) {
cout << b << endl;
}
void g(const string &b) {
cout << b << endl;
}
void f(string &&a) {
g(std::forward<string>(a));
}
int main()
{
f("1122");
string a("222");
f(a);
return 0;
}
I mean "void f(string &&a)" and "void f(const string &a)" can combine in one. Then we just need to call "void f(string &&a)", which can both receive rvalue reference and lvalue by preface forward.
--------- Add description
this may be call universal reference