my git :?https://github.com/hejiawang
?
从Java到c++的学习之路!!
?
? ? ? ?在Java中,只要方法定义出来,无论在调用前还是调用后,就能够使用了;但是在C++中,如果在定义前就调用了,那么要有一个函数声明,也就是函数原型。
?
#include <iostream> using namespace std; void simon(int);//函数原型(函数声明) int main(){ cout << "my first C++ project"; cout << endl; //另起一行 simon(5); //自定义函数 cin.get(); return 0; } void simon(int b){ cout << "a int num is " << b; }
?
? ? ? ? 当然,如果先进行了函数定义,在使用这个函数,就不用函数声明了,其实就是先使用还是先定义的区别,在Java中,这是没有的。。。
#include <iostream> using namespace std; void simon(int b){ cout << "a int num is " << b; } int main(){ cout << "my first C++ project"; cout << endl; //另起一行 simon(5); //自定义函数 cin.get(); return 0; }
?
?
原文:http://hejiawangjava.iteye.com/blog/2248364