---
title: "类指针"
author: "koliy"
date: "2012-09-27T10:51:19Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2012-09-27T10:51:19Z"
id: 1686563
url: "https://koliy.iteye.com/blog/1686563"
---

```
 #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;
}
```