81-85.c++个人练习。
来源:互联网 发布:深入浅出mysql 百度云 编辑:程序博客网 时间:2024/06/07 07:38
1.
class Cat {public:Cat(int age) :itsAge(age) {numOfCats++;}virtual ~Cat() {numOfCats--;}virtual int getAge() {return itsAge;}virtual void setAge(int age) {itsAge = age;}static int getNumOfCats() {return numOfCats;}private:int itsAge;static int numOfCats;};int Cat::numOfCats = 0;void telepathicFunction();int main() {const int maxCats = 5;Cat *catHouse[maxCats];int i;for (i = 0; i < maxCats; i++) {catHouse[i] = new Cat(i);telepathicFunction();}for (i = 0; i < maxCats; i++) {delete catHouse[i];telepathicFunction();}return 0;}void telepathicFunction() {cout << "There are " << Cat::getNumOfCats() << " cats alive!\n";}
2.
#include "my_x_y_z.h"int main() {X x;Z z;z.f(&x);return 0;}
#ifndef MY_X_Y_Z_Hclass X; class Y {public:void g(X*);};class X { private:int i;public:X(){i=0;}friend void h(X*);friend void Y::g(X*);friend class Z;};void h(X* x) { x->i =+10; }void Y::g(X* x) { x->i ++; }class Z {public:void f(X* x) { x->i += 5; }};#endif// MY_X_Y_Z_H
阅读全文
0 0
- c个人练习
- 81-85.c++个人练习。
- 91-95.c个人练习。
- C++Primer Plus 第二章编程练习个人答案
- C++Primer Plus 第三章编程练习个人答案
- C primer plus 第五章 编程练习个人答案
- C primer plus C 第六章控制语句:循环 编程练习个人练习
- C primer plus 第三章编程练习(个人练习答案)
- 个人的MATLAB练习
- 个人练习基地
- 数组,个人练习,0928
- java个人练习
- c++个人练习
- 28-29.个人练习。
- 31-35.个人练习
- 36-40.个人练习
- 46-52.个人练习。
- 71-75.个人练习。
- 2016-2017大三下学期末
- base64
- ARM NEON 基本指令集介绍
- 互联网公司的“敏捷开发”流程是怎么样的,每个职位的角色和分工是什么?
- 位置式和增量式PID控制 .
- 81-85.c++个人练习。
- |Poj 3581|后缀数组|Sequence
- leetCode刷题归纳-backtracking(79. Word Search)
- 程序员的自我修养——7、动态链接
- IDEA配置jdk
- java关键字-final
- 中国考试机器人挑战高考题,最高得分105
- 毕业了,新的开始
- Python初识