Have always thought that C + + is shaped like
int func ();
Such a function declares its meaning as a function of a parameter void (without arguments). Today, however, when I look at C + +, I suddenly see this sentence:
For functions with empty parameter tables, C and C + + differ greatly. In the C language, declare int func2 (); "A function that can take any number of arbitrary arguments (arbitrary numbers, any type)." This interferes with type checking. In the C+ + language, it means "functions without parameters".
The teacher did not say, the school textbooks did not mention, with curiosity, I deliberately tried
TEST.c
1#include <stdio.h>2 3 voidFun ();4 intMain ()5 {6Fun1,1);7 8 return 0;9 }Ten One voidFunintAintb) A { -printf"%d\n", A +b); -}
-wall test.c-o test$./test
2
$ mv test.c test.cpp$ G+ +-wall test.cpp-o testtest.cpp: in function 'int main () ': test.cpp: 6:Error: Too many arguments to function ' void fun ' (11 ); ^test.cpp:3:6void fun (); ^~~
It also explains why the main function is written like this.
int Main (void)
Different meanings of omitting parameters in function declarations of C and C + +