我试图从 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/