does it happen because the compiler creates a temporary string that is passed to the argument or the function?
Yes, and temporaries are allowed to bind to const
lvalue references. The temporary string v
is alive for the duration of the function call.
Note that this is possible because std::string
has a implicit converting constructor with a const char*
parameter. It is the same constructor that makes this possible:
std::string s = "foo";