在C++中,我倾向于在某些情况下省略参数的名称.但是在C中,当我省略参数的名字时出错了.
这是代码:
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\n");
}
void foo(int) //definition in C++, it can compile with g++
{
cout << "in foo" << endl;
}
Run Code Online (Sandbox Code Playgroud)
这是为什么?我不能省略C函数定义中的参数名称吗?