I'm very confused why range-for
uses a ref in my example?
#include <vector>
#include <unordered_map>
using namespace std;
int main()
{
const unordered_map<char, string> d2c_map= { {'1', "abc"} };
const string digits{"1"};
vector<string> R;
for(const auto c : d2c_map.at(digits[0])) {
R.push_back(c); // <-------------------------???
}
return 0;
}
Error indicates that the type of c is const char&
:
error: no matching function for call to 'std::vector<std::__cxx11::basic_string<char> >::push_back(const char&)'