用对象指针引用对象数组2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<iostream>
using namespace std;
class A
{
int x;
public:
void set_x(int a)
{x=a;}
void show_x()
{cout<<x<<endl;}
};
void main()
{
A *ptr,ptr1;
ptr1.set_x(3);
ptr1.show_x();
ptr=&ptr1;//注意:取地址
ptr->show_x();
}