与公开暴露相关的 C++ 项目结构 headers

Project structure in C++ in relation to publicly exposed headers

我试图理解 C++ 中的项目结构,但我发现很难理解 class 结构和 header 文件。

第 1 条摘录(链接在此 post 底部)

By convention, include directory is for header files, but modern practice > suggests that include directory must strictly contain headers that need to be exposed publicly.

我对这个过程的第一个问题是关于 include 目录中的一个单独的 class 文件。

暴露你的 header 的目的是什么?

在此基础上,查看公开的 header 文件的示例。 Link编入以下 GH 存储库:https://github.com/AakashMallik/sample_cmake

Game_Interface class 与 Game_Engine 有什么关系?

game_interface.h

#pragma once

#include <game_engine.h>

class GameInterface
{
  private:
    GameEngine *game;

  public:
    GameInterface(int length);
    void play(int num);
};

我曾在其他地方查找过此过程的简单解释,但到目前为止,我所发现的是在此示例的上下文中无法理解的内容。

对网络技术中的 C++ 背景相当陌生。

Link 到第 1 条:https://medium.com/heuristics/c-application-development-part-1-project-structure-454b00f9eddc

曝光你的header的目的是什么?

有时您可能正在开发一些功能或库。您可能希望通过共享代码的功能来帮助其他人或客户。但是您不想分享确切的工作细节。

例如,您希望分享一个应用漂亮滤镜的图像处理功能。但与此同时,您不希望他们确切地知道您是如何实施的。对于这种情况,您可以创建一个 header 文件,比如 img_filter.h 具有函数声明 -

bool ApplyFilter(const string & image_path);  

现在您可以在 img_filter.cpp 中实施全部细节:

bool ApplyFilter(const string & image_path)
{
....
    // Implementation detail
...
}

接下来你可以准备这个文件的dll,供你的客户端使用。对于工作、参数、使用等方面的参考,您可以分享img_filter.h

与界面的关系:
定义良好的接口通常很好,因此您可以透明地更改实现细节,这意味着 HOW 您实现细节并不重要,只要接口或函数名称和参数保持不变。