您的位置:首页 > 其它

第5周项目--程序阅读——指针、const、static

2015-04-05 15:30 225 查看
#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;}     <span style="color:#ff0000;">//要用this指针区别
</span>};//base_end

int main()
{
    base *ptr;        <span style="color:#ff0000;">//定义指向类类型的指针
</span>    ptr=new base[2];   <span style="color:#ff0000;">//开辟动态存储,数组
</span>    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;
}
具体的示例了怎样用动态空间的指针数组

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: