项目 A,PA.h:
#include "Common.h"
class PA
{
void func()
{
Common::getInstance()->cm();
Common::getInstance()->onlyCallByPA();
}
}
项目通用,Common.h:
class Common
{
SINGLETON
public:
void cm(){}
private:
//I do not want PB to call onlyCallByPA
//so I want to add class PA to friend class
//so I need to include PA.h
//but if I include PA.h, PB.cpp include PA.h
//this will make PA.h expose to PB
//I do not want PB to include PA.h
void onlyCallByPA(){}
}
项目 B,PB.cpp:
#include "Common.h"
class PB
{
//I need to call cm() but PB do not be allowed to call onlyCallByPA
//and also do not be allowed to include PA.h
}
所以我想做PA
asCommon
的朋友班,但这会引入依赖PB
。
有更好的解决方案吗?或者,我可以使用其他设计来实现我想要的吗?