第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; }具体的示例了怎样用动态空间的指针数组
相关文章推荐
- 《C++语言基础》程序阅读——指针、const、static(二)
- 《C++语言基础》程序阅读——指针、const、static(一)
- 《C++语言基础》程序阅读——指针、const、static
- 第15周项目2阅读程序(指针+条用函数)
- 第五周项目零:阅读程序(5):static
- 第十六周项目二(2) 阅读指针程序
- 《C++语言基础》实践项目——指针、const、static
- 第5周项目--程序阅读
- 第十五周项目2-程序阅读(对指针的理解1)
- 第五周项目零:阅读程序(4):const
- 第九周项目:程序阅读 类和指针
- 第九周项目:阅读程序 类和指针
- 第5周-项目0-阅读程序
- 第5周项目--程序阅读
- 第十五周项目2-程序阅读(对指针的理解2)
- 第十二周项目1-1:阅读程序(static变量
- 专访许鹏:谈C程序员修养及大型项目源码阅读与学习
- 第十周项目一 (程序填充与阅读) 1:
- 专访许鹏:谈C程序员修养及大型项目源码阅读与学习
- 二级指针、函数指针、枚举、static、const