繁体   English   中英

由于头文件中的语法错误而导致编译错误

[英]Compile error due to syntax error in header file

我有一个依赖于几个包含文件的程序。 当我按照下面显示的顺序定义include时,程序可以正常编译。

#include <iostream>
#include "opencv2/cvconfig.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/internal.hpp" // For TBB wrappers
#include "arrayfire.h"

但是,当我切换后两个包括时,如下所示

#include <iostream>
#include "opencv2/cvconfig.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "arrayfire.h"
#include "opencv2/core/internal.hpp" // For TBB wrappers

我收到编译器错误:

1> d:\\ libraries \\ tbb41 \\ tbb41_20130613oss \\ include \\ tbb \\ task.h(765):错误C2059:语法错误:'{'1> d:\\ libraries \\ tbb41 \\ tbb41_20130613oss \\ include \\ tbb \\ task.h( 765):错误C2334:“ {”之前的意外令牌; 跳过表观功能体

这是意外的,我想修复它。 所有包含的内容都来自库(OpenCV和ArrayFire)。 关于可能的原因以及如何解决此问题的任何建议?

编辑这是task.h的相关部分:

759 #if __TBB_TASK_GROUP_CONTEXT
760    //! This method is deprecated and will be removed in the future.
761    /** Use method group() instead. **/
762    task_group_context* context() {return prefix().context;}
763
764    //! Pointer to the task group descriptor.
765    task_group_context* group () { return prefix().context; }
766 #endif /* __TBB_TASK_GROUP_CONTEXT */

在765行中,IDE抱怨{ ,说Error: expected an identifier

这是由ArrayFire标头之一中的以下错误引起的:

#define group(...)  __VA_ARGS__

这定义了一个类似于函数的宏,该宏将替换为宏参数列表。 group(a,b)扩展为a,b ,并且(这里更重要的是) group()扩展为无。 由于宏不尊重诸如作用域之类的语言级概念,因此会干扰后面的声明:

task_group_context* group () { return prefix().context; }

转换成

task_group_context* { return prefix().context; }

这不是有效的声明。

解决方法是最后包含"arrayfire.h" ,并注意您尝试在自己的代码中使用哪些名称; 或将其#undef group (以及可能造成的其他任何恶果)。 或者,如果可能的话,用火将其杀死,并使用更少邪恶的东西代替。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM