클래스 포인터

977 단어 포인터
 #include<iostream>
 using namespace std;
 class Student
 {
 	public :
 		void set();
 		void show();
 	private:
 		int num;
 		int data;
 };
 
 void Student::set()
 {
 	cout<<"please input one student num:";
 	cin>>num;
 	cout<<"please input one student data:";
 	cin>>data; 		
}
 
 void Student::show()
 {
 	cout<<"the student num:"<<num<<"and data:"<<data<<endl;
 	
}
 
 int main()
 {
 	Student std[5];
	Student *p;
	p=&std[0];
	int i=0;
	while(i<5)
	{
		//(*p).set();
		(*(p+i)).set();
		cout<<"ok>>end:"<<++i<<endl;
	}
	(*p).show();
	(*(p+2)).show();
	(*(p+4)).show();
 
 return 0;
}

좋은 웹페이지 즐겨찾기