在我的代码中,我使用boost(1.52)和qt(4.8.3),我遇到的第一个编译错误如下
D:\qt\4.8.3\x86_64-w64-mingw32\include/QtCore/qglobal.h:2439:21: error: 'boost::Q_FOREACH' has not been declared
Run Code Online (Sandbox Code Playgroud)
这是一个错误吗?
suc*_*uch 10
用#include <QObject>.启动你的.cpp文件.
例如,这个:
#include <boost/foreach.hpp>
#include <QObject>
#include <boost/multi_index/hashed_index.hpp>
Run Code Online (Sandbox Code Playgroud)
...汇编到error: 'boost::Q_FOREACH' has not been declared这个:
#include <QObject>
#include <boost/foreach.hpp>
#include <boost/multi_index/hashed_index.hpp>
Run Code Online (Sandbox Code Playgroud)
......编译得很好.
qglobal.h(包含在所有Qt头文件中)创建一个宏#define foreach Q_FOREACH,该宏在引用中扩展为boost::foreach::fooor namespace foreach,但仅在宏声明后遇到的引用中扩展.要尽早定义宏,所有引用都以相同的方式扩展.
我hashed_index.hpp在示例中使用,因为它碰巧使用foreach命名空间.重命名命名空间很难看,但它不会影响客户端代码.