Whey we cannot Convert pointer to a character ->TO-> a reference to a pointer to a constant character
I am interested in knowing the reason of syntax error when we call foo_ptr. When foo_char is allowed why not foo_ptr.
[Update 1.] I would be happy in knowing the reason that foo_char()
is working, why foo_ptr()
is not working .. What happens when pointer come in the picture.
[Update 2.]
Didnt work in Dev C++ compiler version 4.9.9.2 too ..
//code
//OS : Win XP
//Env: VC++ 2008
//NOT ALLOWED
void foo_ptr(const char * & ptr) //reference to a pointer to a constant character
{
return;
}
//allowed
void foo_char(const char & p_Char) //reference to a constant character
{
return;
}
int main()
{
char ch = 'd';
char *ptr = "anu";
foo_char(ch);
foo_ptr(ptr); //NOT ALLOWED syntax error, vc++, 2008
return 0;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…