how does c++ understand which function must to 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.