gpt4 book ai didi

c++ - 在包含中使用定义的值

转载 作者:太空宇宙 更新时间:2023-11-04 01:30:07 25 4
gpt4 key购买 nike

我有 #include文件结构如下:

#include <core/mod1/file1.hpp>
#include <core/mod1/file2.hpp>
#include <core/mod1/mod2/.../modN/fileN.hpp>

每个文件中都有这样的包含。例如,在文件 core/mod1/file1.hpp 中可能有 #include <core/mod3/file5.hpp> .这里core是我的图书馆的名字。但我想用 core_new而不是 core在整个项目中,没有修改所有文件(实际上很多)。我试图添加 #define core core_new ,希望它能替代我需要的东西:

#define core core_new
#include <core/mod1/file1.hpp>
#include <core/mod1/file2.hpp>
#include <core/mod1/mod2/.../modN/fileN.hpp>

但它并没有这样做:core/mod1/file1.hpp被包含而不是 core_new/mod1/file1.hpp .有办法实现吗?

最佳答案

您想使用文件系统,而不是 C++ 编译器。创建一个新目录并将所有源文件复制/链接到那里。将编译器中的 -I 选项更改为使用这个新目录。当然,将新文件放在新的 core 目录中。这样您就不需要编辑单个源文件/头文件。

关于c++ - 在包含中使用定义的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24141827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com