C++之函数原型
函数声明和定义出现在主函数之后的,都需要在函数调用之前加函数原型声明;
即以下两段代码是等效的:
# include <iostream>
void simon(int); //function prototype for simon()
int main(){
using namespace std;
simon(3);
cout << "Pick an integer: ";
int count;
cin >> count;
simon (count);
cout << "Done!" <<endl;
return 0;
}
void simon (int n){
using namespace std;
cout << "Simon says touch your toes " << n <<" times." <<endl;
}
# include <iostream>
void simon (int n){
using namespace std;
cout << "Simon says touch your toes " << n <<" times." <<endl;
}
int main(){
using namespace std;
simon(3);
cout << "Pick an integer: ";
int count;
cin >> count;
simon (count);
cout << "Done!" <<endl;
return 0;
}