变量和参数用小写字母开头的单词组合而成
变量和参数用小写字母开头的单词组合而成。 例如: BOOL flag; int drawMode;
1 #include <iostream> 2 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 4 using namespace std; 5 class ex_class { 6 int value; 7 public: 8 ex_class(int n) { 9 value=n; 10 cout << "Stack initialized." << endl; 11 } 12 ~ex_class() { 13 cout << "The Object destroyed." <<endl; 14 } 15 void set_value(int n); 16 void show_val(char *name); 17 } ; 18 19 //在类外定义内联成员函数 20 inline void ex_class::set_value(int n) { 21 value=n; 22 } 23 //在类外定义非内联成员函数 24 void ex_class::show_val(char *name) { 25 cout<<name<<": "; 26 cout<<value<<endl; 27 } 28 //在main()函数中测试ex_class类 29 int main(int argc, char** argv) { 30 //创建对象x和y 31 ex_class x(100),y(200); 32 33 //显示对象的数据 34 x.show_val("x"); 35 y.show_val("y"); 36 37 //设置新值给对象 38 x.set_value(1); 39 y.set_value(2); 40 41 //显示对象的数据 42 x.show_val("x"); 43 y.show_val("y"); 44 45 return 0; 46 return 0; 47 }