例:Test.cpp对应Test.h;Open.cpp对应Open.h;
那么必须在相应的cpp文件中预提示相应的头文件;在Test.cpp中必须有#include"Test.h",
在Open.cpp中必须有#include"Open.h",在主函数中必须有#include"Test.h"和 #include"Open.h",才能调用相对应CPP中的函数及其他东西;
当然宽尺也可以 Test.cpp和Open.cpp 同时对应Test.h;
在Test.cpp中必须有#include"Test.h",在Open.cpp中必须有#include"Test.h",在主函数中必须有段嫌#include"Test.h"才能调用相应两个CPP中的函数及其他东西;
//文件A.hclass CInterface
class CA
{
public:
CA(CInterface* pinterface)
{
m_pInterface = pinterface
}
void fun_a()
{
printf("fun_a\r\n")
}
CInterface* m_pInterface
}
//文件B.h
class CInterface
class CB
{
public:
CB(CInterface* pinterface)
{
m_pInterface = pinterface
}
CInterface* m_pInterface
}
//文件C.h
class CInterface
class CC
{
public:
CC(CInterface* pinterface)
{
m_pInterface = pinterface
}
CInterface* m_pInterface
}
//接口文件类
class CA
class CB
class CC
class CInterface
{
public:
void create_obj()
{
m_pa = new CA(this)
m_pb = new CB(this)
m_pc = new CC(this)
}
CA* get_a()
{
return m_pa
}
CB* get_b()
{
return m_pb
}
CC* get_c()
{
return m_pc
}
private:
CA* m_pa
CB* m_pb
CC* m_pc
}
int main()
{
CInterface test
test.create_obj()
//文件c调用侍李文件a的过程
//通过这种方法,可以访问所有文件,腔谈罩且实现分离
test.get_c()->伍闹m_pInterface->get_a()->fun_a()
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)