解决两类相互包含使用另一个类成员函数
2015-07-15 22:27
274 查看
// VistorMode.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <IOSTREAM> using namespace std; class B; class A{ public: /* void getBaction(B * p){ p->action(); //会出错,error:use of undefined type 'B' //因为前面只声明了这个类,但类的成员函数还未知,只能定义一个B类型的指针 } */ void getBaction(B * p); //实现放于B的action声明定义后面 void action(){ cout<<"action in A"<<endl; } }; class B{ public: void getAaction(A * p){ p->action(); } void action(){ cout<<"action in B"<<endl; } }; void A::getBaction(B * p){ p->action(); } int main(int argc,char * argv[]){ A a ; B b ; a.getBaction(&b); b.getAaction(&a); return 0; }
相关文章推荐
- [leedcode 86] Partition List
- 6 Keroa
- 用户管理命令
- cocos2d学习之旅(二)
- 访问者模式 Vistor
- nginx 1.6.2源码分析2 499问题之upstream
- apache虚拟机配置
- 学习CSS(5)
- 从CRF测试结果中提取出连续的标注行
- ImageSwitcher和TextSwitcher使用笔记
- 算法面试题总结
- 内存映射文件
- leetcode-153-Find Minimum in Rotated Sorted Array
- Hive Cilent数据操作
- 下沙的沙子有几粒?(hdu1267)递推
- winform打开进程与关闭进程
- 每日一算法之拓扑排序
- C语言语句篇
- MAP
- Android studio 报错 Failed to complete Gradle execution already disposed:module:'***'