我有 C++ 中的代码
#include<vector>
std::vector<double> foo;
我需要为嵌入式平台编译此代码,该平台使用名为 uSTL 的 STL 自定义实现。 .使用它需要 #include
ing ustl.h
头文件和 all STL classes are defined in another namespace .因此,上面的代码片段应该变成
#include<ustlh.>
ustl::vector<double> foo;
我不想修改源代码,因为它是其他非嵌入式应用程序使用的库代码。我正在考虑使用 C 预处理器来转换 #include<vector>
至 #include<ustl.h>
但这似乎是不可能的(宏名称必须是有效的标识符)。
是否有其他方法让 C 预处理器执行此操作?还是有其他不修改原始源代码的方法?
最佳答案
你必须做类似的事情:
#ifdef USE_USTL
#include <ustl.h>
using ustl::vector;
#else
#include <vector>
using std::vector;
#endif
vector<double> foo;
关于c++ - 有没有办法让 C 预处理器更改我正在使用的 STL 实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40820405/