C++ 预期的 ; 在顶级声明符之后,xcode 中出现错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17129698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 20:56:51  来源:igfitidea点击:

Expected ; after top level declarator, error in xcode

c++cxcode

提问by cube

I am working with this utils.cfile in xcode, which has the following:

我正在xcode 中使用这个utils.c文件,它具有以下内容:

 #if FF_API_AVCODEC_OPEN
    int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
    {
        return avcodec_open2(avctx, codec, NULL);
    }

It's causing an Expected ; after top level declarator, error (during build) in xcode at this line: int attribute_align_arg avcodec_open(....

Expected ; after top level declarator在 xcode 中的这一行导致, 错误(在构建期间):int attribute_align_arg avcodec_open(....

Why? and what should I do to resolve this.

为什么?我该怎么做才能解决这个问题。

Thank you.

谢谢你。

回答by Zord

I ran into this error when using the auto completion.

我在使用自动完成时遇到了这个错误。

When inserting the parameter of a function, XCode will insert placeholders that need to be edited but show as completely valid C++ in the GUI.

当插入函数的参数时,XCode 将插入需要编辑但在 GUI 中显示为完全有效的 C++ 的占位符。

It took me some hours until I checked my file in another editor, revealing that instead of the expected:

我花了几个小时,直到我在另一个编辑器中检查我的文件,发现而不是预期的:

void func(int a)

void func(int a)

XCode had actually inserted

XCode实际上已经插入

void func(<#int a#>)

void func(<#int a#>)

In the XCode editor the parameter shows as int awith a light blue background, so it isn't easy to spot as the source of the compiler error.

在 XCode 编辑器中,参数显示为int a浅蓝色背景,因此不容易识别为编译器错误的来源。

回答by owenfi

I ran into this after moving a class to a dynamic library but leaving the old import around. Commenting out the old import resolved the issue (but it wasn't the first thing I looked for as the dynamic library import was earlier and also showed an error).

在将类移动到动态库但保留旧的导入后,我遇到了这个问题。注释掉旧的导入解决了这个问题(但这不是我寻找的第一件事,因为动态库导入更早并且还显示了错误)。

回答by Prateek Sharma

I got a similar error in xcode for the following code:

对于以下代码,我在 xcode 中遇到了类似的错误:

#ifndef Parser_hpp
#define Parser_hpp

#include <string>
std::string getTitle();

#endif /* Parser_hpp */

The reason was that the code had to be wrapped with C++ preprocessor directives. Like so:

原因是代码必须用 C++ 预处理器指令包装。像这样:

#ifndef Parser_hpp
#define Parser_hpp
#if defined __cplusplus

#include <string>
std::string getTitle();

#endif /* __cplusplus */
#endif /* Parser_hpp */