你可以看看pimpl成语.基本上,只公开客户端应该和可以在公共接口中使用的内容,并保留其他所有内容:
// scene_interface.h
class SceneImpl; //only forward-declare
class Scene
{
// client-visible methods, and that's all
// no implementation details
private:
SceneImpl* pImpl; // <- look, the name
};
// scene_impl.h & scene_impl.cpp
// hidden from the client
class Mesh
{
//...
};
class SceneImpl
{
Mesh* pMesh;
//etc.
};
Run Code Online (Sandbox Code Playgroud)