用对象指针引用对象数组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream.h>
//using namespace std;
class A
{
int x;
public:
void set_x(int a)
{x=a;}
void show_x()
{cout<<x<<endl;}
};
main()
{
A *ptr,ptr1[2];
ptr1[0].set_x(12);
ptr1[1].set_x(22);
ptr=ptr1;
ptr->show_x();
ptr++;
ptr->show_x();
return 0;


}