how does c++ understand which function must to use? in this code:

    void AdptSendReply(const char* str)
{
    string s(strlen(str) + 2);
    s = str;
    AdptSendReply(s);
}

void AdptSendReply(const string&amp; str)
{
    string s(str.length() + 2);
    AdptSendReply(s); // use the next one
}

void AdptSendReply(string&amp; str)
{
    if (AdapterConfig::instance()-&gt;getBoolProperty(PAR_LINEFEED)) {
        str += "\r\n";
        AdptSendString(str);
    }
    else {
        str += "\r";
        AdptSendString(str);
    }
}


i think c++ use of overloading ability.but how it can recognize which of the two functions "void AdptSendReply(string&amp; str)" or "void AdptSendReply(const string&amp; str)" must use?!
The compiler decides which function to use based on the variable type information. Imagine you write

str += "test";


If you declare str as a constant, the above line will throw an error. So if you write AdptSendReply(str) instead, the compiler will call the const function. Likewise, if you declare str as a mutable variable, the above line will compile fine, and, should you call AdptSendReply(str), the compiler will use the non-const function.