64,660
社区成员
发帖
与我相关
我的任务
分享
// A.h
#ifndef _A_H_
#define _A_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.h
#ifndef _B_H_
#define _B_H_
class A;
class B
{
public:
void funB()
{
printf("B...\n");
A::getTheApp().funA();
}
void funB2();
};
#endif
// B.cpp
#include "stdafx.h"
#include "B.h"
void B::funB2()
{
printf("funB2...\n");
}
#include "stdafx.h"
#include "A.h"
#include "B.h"
int main(int argc, _TCHAR* argv[])
{
A a;
a.funA();
A::getTheApp().funA();
B b;
b.funB();
return 0;
}
#ifndef _A_H_
#define _A_H_
class A
{
public:
static A& getTheApp();
void A::funA() {
printf("funA...\n");
}
private:
static A* theApp;
};
#include "B.h"
#endif
// A.h
#ifndef _A_H_
#define _A_H_
#include "B.h"
class A
{
public:
static A& getTheApp();
void A::funA() {
printf("funA...\n");
}
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;
}
// B.h
#ifndef _B_H_
#define _B_H_
#include "A.h"
class B
{
public:
void funB()
{
printf("funB...\n");
A::getTheApp().funA();
}
};
#endif
// B.cpp
#include "stdafx.h"
#include "B.h"
#include "stdafx.h"
#include "A.h"
#include "B.h"
int main(int argc, _TCHAR* argv[])
{
A a;
a.funA();
A::getTheApp().funA();
B b;
b.funB();
return 0;
}
// B.h
#include "A.h"
// ...
A::getTheApp().funA();// 包含了,还是提示:has not been declared