第五周 阅读程序 1
来源:互联网 发布:淘宝账号怎么找回 编辑:程序博客网 时间:2024/05/08 18:12
/**Copyright (c)2014,烟台大学计算机与控制工程学院*All rights reserved.*文件名称:d.cpp*作 者:张旺华*完成日期:2015年3月25日*版 本 号:v1.0*/#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_endint main(){ base *ptr; //建立指向对象的指针 ptr=new base[2]; //建立两个对象数组,没有赋值,调用无参构造函数 ptr->set(30); //对数组第一个对象进行赋值。 ptr=ptr+1; //ptr+1使ptr指向数组中的第二个对象 ptr->set(50); //调用set()函数你,运用this指针 base a[2]= {1,9}; //在建立两个对象数组,调用有参构造函数。 cout<<a[0].get()<<","<<a[1].get()<<endl; cout<<ptr->get()<<","; ptr=ptr-1; //使ptr指向对象数组第一个对象 cout<<ptr->get()<<endl; delete[] ptr; //调用析构函数 return 0;}
阅读程序分析:见程序批注
0 0
- 第五周程序阅读(1)
- 第五周 阅读程序 1
- 第五周阅读程序 1
- 第五周程序阅读
- 第五周阅读程序
- 第五周 程序阅读
- 第五周 阅读程序(1)
- 第五周 阅读程序(1)--指针
- 第五周 程序阅读(1)
- 第五周程序阅读(2)
- 第五周程序阅读(3)
- 第五周程序阅读(4)
- 第五周程序阅读(5)
- 第五周程序阅读(6)
- 第五周阅读程序一
- 第五周阅读程序二
- 第五周阅读程序三
- 第五周程序阅读四
- 每天一练 2015/04/06 widget的用法
- Java jvisualvm简要说明
- JS中打印DIV
- CEdit一行一行读取字符串
- a_time--授权部分及所用知识点(含转载CONST&)
- 第五周 阅读程序 1
- 实现下拉刷新
- hdu 4006 The kth great number/SBT
- c语言节点定义
- 搜索二叉树
- unity 联机调试(android ios)
- NSOperation
- 草根做项目的经验分享二
- POJ1811 Prime Test