自考新教材-p146_4(1)

源程序:

#include <iostream>
using namespace std;

class base
{
private:
int m;
public:
base() {};
base(int a) :m(a) {}
int get()
{
return m;
}
void set(int a)
{
m = a;
}
};
int main()
{
base *ptr = new base[2];
ptr->set(30);
ptr = ptr + 1;
ptr->set(50);
base a[2] = {1,9};
cout << a[0].get() << "," << a[1].get() << endl;
cout << ptr->get() << ",";
ptr = ptr - 1;
cout << ptr->get() << endl;
delete[]ptr;
system("pause");
return 1;
}

运行结果:

 

posted @ 2020-02-06 20:04  bobo哥  阅读(141)  评论(0编辑  收藏  举报