<分区>
比较
int foo (int n) {
return n;
}
对比
int foo(int);
int foo (int n) {
return n;
}
是否有任何理由事先在 C++ 中声明函数原型(prototype)?我来自 JAVA 背景,所以我从来没有声明过函数原型(prototype),这对我来说有点新鲜。
标签 c++
<分区>
比较
int foo (int n) {
return n;
}
对比
int foo(int);
int foo (int n) {
return n;
}
是否有任何理由事先在 C++ 中声明函数原型(prototype)?我来自 JAVA 背景,所以我从来没有声明过函数原型(prototype),这对我来说有点新鲜。
最佳答案
不,如果被调用函数写在调用函数之前,则不需要编写原型(prototype)。编写原型(prototype)是为了让编译器能够理解声明的函数是稍后定义的。所以在那种情况下,即使被调用函数写在调用函数之后,它也不会引发任何错误。
关于c++ - 有必要声明函数原型(prototype)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22208446/