第五周 课后实践:程序阅读(1)

来源:互联网 发布:宁波网络继续教育 编辑:程序博客网 时间:2024/06/05 15:34

问题及代码:

#include <iostream>using namespace std;class base{private:    int m;public:    base() {};    base(int m){this->m=m;}    int get(){return m;}    void set(int m){this->m=m;}};//base_end  int main(){    base *ptr;    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;    return 0;}

运行结果:
0 0
原创粉丝点击