首先,本文中讨论的例子采用C语言,而非C++语言。
使用示例分析这个问题:
例子1
#include <stdio.h>
void hello(int a);
void hello(int a, int b);
void hello(int a)
{
printf("hello, %d\n", a);
}
void main()
{
hello(1);
}
在这个例子中,hello()函数声明了两次,定义了一次。
VS2010的编译结果为:
xx.c(4): warning C4031: second formal parameter list longer than the first listxx.c(7): warning C4029: declared formal parameter list different from definition
VC6的编译结果为:
xx.c(4) : warning C4031: second formal parameter list longer than the first list
xx.c(7) : warning C4029: declared formal parameter list different from definition
xx.c(13) : error C2198: 'hello' : too few actual parameters
例子2
#include <stdio.h>
void hello(int a);
void hello(int a, int b);
void hello(int a)
{
printf("hello, %d\n", a);
}
void hello(int a, int b);
void main()
{
hello(1);
}
例子2比例子1多了一个函数声明(红色部分)。
在这个例子中,hello()函数声明了三次,定义了一次。
VS2010的编译结果为:
xx.c(4): warning C4031: second formal parameter list longer than the first list
xxc(7): warning C4029: declared formal parameter list different from definition
xx.c(11): warning C4031: second formal parameter list longer than the first list
xx.c(15): error C2198: 'hello' : too few arguments for call
VC6的编译结果为:
<