Today I just want to raise the question about the argument of the C ++ template function template and the resolution of template overload in C ++ 11 (I use vs2010 sp1). I defined two template functions as shown below:
function # 1:
template <class T>
void func(const T& arg)
{
cout << "void func(const T&)" <<endl;
}
function # 2:
template <class T>
void func(T&& arg)
{
cout << "void func(T&&)" <<endl;
}
Now consider the following code:
int main() {
{int a = 0; func(a);}
{const int a = 0; func(a);}
{func(0);}
{func("feng")}
{char array[] = "feng"; func(array);}
}
I just want to know the rules underlying the definition of the overload function in these scenarios.
I disagree with the two answers below. I think the const int example is different from the string example. I can slightly change #function 1 to see that the type being deduced is on the ground
template <class T>
void func(const T& arg)
{
T local;
local = 0;
cout << "void func(const T&)" <<endl;
}
const int a = 0;
func(a);
template <class T>
void func(const T& arg)
{
T local;
Local[0] = ‘a’;
cout << "void func(const T&)" <<endl;
}
Func("feng");
const int, const "const T &" "" const int; , "const T &" . int & const ( int * const)