M
miaohua1982
the code as follows:
#include<iostream>
using namespace std;
template <int N>
void foo( const char (&str)[N])
{
cout<<"array"<<endl;
}
template <typename T>
void foo(const T& str);
template <>
void foo(char *const &str)
{
cout<<"char *"<<endl;
}
int main()
{
char arr[10];
foo(arr);
}
why the called function is the void foo(const char(&str)[N])? I test
the code by VC7, the output is
*array*, but according to my knowledge, the following code is also
OK:
char p[1];
char * const & str = p;
so why the output is not *char*? I mean the why the *exact match*
funcion is not the secnod "foo" with params (char *const &str)?
It has confused me so much. Is there anyone call tell me?
Thank you very much!
#include<iostream>
using namespace std;
template <int N>
void foo( const char (&str)[N])
{
cout<<"array"<<endl;
}
template <typename T>
void foo(const T& str);
template <>
void foo(char *const &str)
{
cout<<"char *"<<endl;
}
int main()
{
char arr[10];
foo(arr);
}
why the called function is the void foo(const char(&str)[N])? I test
the code by VC7, the output is
*array*, but according to my knowledge, the following code is also
OK:
char p[1];
char * const & str = p;
so why the output is not *char*? I mean the why the *exact match*
funcion is not the secnod "foo" with params (char *const &str)?
It has confused me so much. Is there anyone call tell me?
Thank you very much!