【发布时间】:2010-10-23 02:36:51
【问题描述】:
我大部分时间都不使用 lib 链接和 dll 进行编码,最近当我这样做时,我意识到我执行 #include 的方式可能有一些非常错误的地方。
以下是执行#include 的正确/理想方式吗?
假设我有 3 个项目 (1) dll_A (2) dll_B (3) exe_1。 dll_A依赖dll_B,exe_1依赖一个dll_A。
我的#include 方法如下:
dll_B.h ----> no dependency
dll_B.cpp -----> #include dll_B.h
dll_A.h -------> #include dll_B.h
dll_A.cpp -------> #include dll_A.h
exe_1.h --------> #include dll_A.h
从这里可以看出 exe_1.h 间接包含 dll_b.h 这对我来说有点不好,因为我希望 exe_1.h 独立于 dll_b.h...但是,我不确定是否是可能的,因为 exe_1 还能如何链接到 dll_b?
编辑:示例依赖
// dll_B.h
struct dataB{};
// dll_A.h
#include dll_B.h
dataB* A_function_ptr(); // (any difference for implementing PIMPL?)
dataB& A_function_ref();
dataB A_function_copy();
// exe_1.cpp
#include dll_A.h
// ... it seems naturally #include-sion of dll_B.h is necessary? Can it be avoided?
【问题讨论】: