64,637
社区成员
发帖
与我相关
我的任务
分享
// A.h
#include "B.h"// 要知道B的定义
template <...>// A.h 中的模版类 CA
class CA
{
public:
void funA()
{
B:funB();// 这里需要知道 B 的完整定义
}
};
// B.h
#include "A.h"// 要包含模版类的定义
class B
{
typedef CA<...> CAlias;// 这里需要使用模版类 CA
CAlias * m_b;
//...
static funB();
};
// A.h
#ifndef _A_H_
#define _A_H_
#include "B.h"
class A
{
public:
static A& getTheApp();
void funA();
private:
static A* theApp;
};
#endif
/////////////////////////////////////////////
// A.cpp
#include "stdafx.h"
#include "A.h"
A* A::theApp = NULL;
A& A::getTheApp()
{
if (theApp == NULL) {
theApp = new A();
}
return *theApp;
}
void A::funA() {
printf("funA...\n");
B b;
printf("i_b = %d\n", b.i_b);
}
////////////////////////////////////////////////
// B.h
#ifndef _B_H_
#define _B_H_
#include "A.h"
class B
{
public:
B(){i_b = 100;}
void funB();
int i_b;
};
#endif
/////////////////////////////////////
// B.cpp
#include "stdafx.h"
#include "B.h"
void B::funB()
{
printf("funB...\n");
A::getTheApp().funA();
}
//////////////////////////////
// 主程序
#include "stdafx.h"
#include "A.h"
#include "B.h"
int main(int argc, _TCHAR* argv[])
{
B b;
b.funB();
return 0;
}