1. 程式人生 > >面向物件的設計方法的概述:

面向物件的設計方法的概述:

2.定義檔案
#include <iostream>
using namespace std;
#include "Stu.h"
void f1() {
//建立Stu類的物件
Stu stu1;//age no name
Stu stu2;//age no name
//訪問成員:  “物件.成員”
stu1.age = 10;
stu1.no = 1;
stu1.name = "小明";


stu2.age = 20;
stu2.no = 2;
stu2.name= "大明";


//stu1: age10,no=1,name=小明
cout<<"stu1: age"<<stu1.age<<",no="<<stu1.no<<",name="<<stu1.name<<endl;


//stu2: age20,no=2,name=大明
cout<<"stu2: age"<<stu2.age<<",no="<<stu2.no<<",name="<<stu2.name<<endl;


stu1.sleep();
stu2.sleep();


stu1.study();
stu2.study();
}
void f2() {
Stu stu1;
Stu &stu2 = stu1;
stu2.age=100;
cout<<stu2.age<<endl;
cout<<stu1.age<<endl;
stu2.sleep();
stu1.sleep();
}
int main() {
//f1();
f2();
return 0;
}





#endif /* STU_H_ */