c++ - boost 预处理器 : Sample not working

标签 c++ boost boost-preprocessor

我试图从 Boost.Preprocessor 编译一个示例库是:

#include <boost/preprocessor/seq/insert.hpp>
#define SEQ (a)(b)(d)
BOOST_PP_SEQ_INSERT(SEQ, 2, c) // expands to (a)(b)(c)(d)

在 Visual Studio 2008 上,我收到错误 error C2065: 'b' : undeclared identifier

样本有问题还是我遗漏了什么??

请注意:序列定义本身是可以的。为了展示这一点,我编译了这段代码:

#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/seq/for_each.hpp>

#define SEQ (w)(x)

#define MACRO(r, data, elem) BOOST_PP_CAT(elem, data)

struct w_
{
 int x;
};
void test()
{
 BOOST_PP_SEQ_FOR_EACH(MACRO, _, SEQ);
    x_.x = 3;
}

免责声明:此代码是 WTF 代码,我从未打算像这样使用 BOOST PP :-)

最佳答案

那么,您正在尝试编译包含以下内容的源文件:

(a)(b)(c)(d)

我想您应该将它放在这段代码有意义的上下文中,或者只运行预处理器(不编译结果)。

关于c++ - boost 预处理器 : Sample not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3977615/

相关文章:

c++ - 如何将 QIcon 转换为 QPixmap

c++ - 如何使用Boost序列化mersenne_twister_engine?

C++ 等价于 Rust 的 Result<T, E> 类型?

c++ - 如何压缩(组合迭代器)不处理 boost::prior

boost - 使用 clang-tidy 处理大量与 boost 单元测试相关的警告

c-preprocessor - C99 预处理器图灵完整吗?

c++ - 一般打印一系列变量及其名称

c++ - 管理 Win32 应用程序和 QWinMigrate 之间的键盘事件

c# - 全屏显示窗口

c++ - BOOST_PP_DEFINED 可以实现吗?