我试图从 BOOST.PREPROCESOR 库是:

#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)

我想您要么将其放在此代码有意义的上下文中,要么只是运行预处理器(不编译结果)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top