I've been trying to understand the way C++ selects templates or member functions. Consider the following code sample:
#include <iostream>
#include <string>
struct Test
{
template<typename X>
explicit Test( X&& s){ std::cout << "1" << std::endl;}
explicit Test( const std::string& s) { std::cout << "2"<< std::endl; }
explicit Test( std::string&& s) { std::cout << "3"<< std::endl; }
};
int main ()
{
std::string line = "TEST";
Test test( line );
}
I'm getting "1" printed on console. Why "2" is not selected if it is a non-template that matches the parameter types?