In C++, I tend to omit the parameter's name under some circumstances. But in C, I got an error when I omitted the parameter's name.
Here is the code:
void foo(int); //forward-decl, it's OK to omit the parameter's name, in both C++ and C
int main()
{
foo(0);
return 0;
}
void foo(int) //definition in C, it cannot compile with gcc
{
printf("in foo
");
}
void foo(int) //definition in C++, it can compile with g++
{
cout << "in foo" << endl;
}
Why is that? Can't I omit the parameter's name in C function definition?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…