Xcode 错误编译 c++ 预期的成员名称或“;” 声明说明符后

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31665095/
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-09-15 07:33:33  来源:igfitidea点击:

Xcode error compiling c++ Expected member name or ';' after declaration specifiers

c++xcodeobjective-c++

提问by user1899201

I'm having issues with the checking methods in a c++ library (openNN) i'm trying to compile in Xcode. I'll use an example of one of the methods as i suspect they are all caused by the same issue.

我在尝试在 Xcode 中编译的 c++ 库 (openNN) 中的检查方法有问题。我将使用其中一种方法的示例,因为我怀疑它们都是由同一问题引起的。

Header declaration where i get the error:
Expected member name or ';' after declaration specifiers.

我收到错误的标题声明:
预期的成员名称或“;” 在声明说明符之后。

void check(void) const;

Function definition:

函数定义:

void InverseSumSquaredError::check(void) const
{
    std::ostringstream buffer;

    // Neural network stuff

    if(!neural_network_pointer)
    {
       buffer << "OpenNN Exception: InverseSumSquaredError class.\n"
              << "void check(void) const method.\n"
              << "Pointer to neural network is NULL.\n";

       throw std::logic_error(buffer.str().c_str());      
    }

    const MultilayerPerceptron* multilayer_perceptron_pointer = neural_network_pointer->get_multilayer_perceptron_pointer();

    if(!multilayer_perceptron_pointer)
    {
       buffer << "OpenNN Exception: InverseSumSquaredError class.\n"
              << "void check(void) const method.\n"
              << "Pointer to multilayer perceptron is NULL.\n";

       throw std::logic_error(buffer.str().c_str());      
    }

    const unsigned int inputs_number = multilayer_perceptron_pointer->count_inputs_number();
    const unsigned int outputs_number = multilayer_perceptron_pointer->count_outputs_number();

    if(inputs_number == 0)
    {
       buffer << "OpenNN Exception: InverseSumSquaredError class.\n"
              << "void check(void) const method.\n"
              << "Number of inputs in multilayer perceptron object is zero.\n";

       throw std::logic_error(buffer.str().c_str());      
    }

    if(outputs_number == 0)
    {
       buffer << "OpenNN Exception: InverseSumSquaredError class.\n"
         << "void check(void) const method.\n"
         << "Number of outputs in multilayer perceptron object is zero.\n";

       throw std::logic_error(buffer.str().c_str());      
    }

    // Mathematical model stuff

    if(!mathematical_model_pointer)
    {
        buffer << "OpenNN Exception: InverseSumSquaredError class.\n"
               << "void check(void) const method.\n"
               << "Pointer to mathematical model is NULL.\n";

        throw std::logic_error(buffer.str().c_str());     
    }

    // Data set stuff 

    if(!data_set_pointer)
    {
       buffer << "OpenNN Exception: InverseSumSquaredError class.\n"
              << "void check(void) const method.\n"
              << "Pointer to data set is NULL.\n";

       throw std::logic_error(buffer.str().c_str());      
    }

    // Final solutions error stuff

}

If i change the definition in the header to
void InverseSumSquaredError::check(void) const;
I end up with the error:
Extra qualification on member 'check'

I'm currently using the dialect C++98 and Library libc++. Xcode is set to compile sources as Objective-C++ which takes care of most of the other errors.

如果我将标题中的定义更改为
void InverseSumSquaredError::check(void) const;
最终出现错误:
成员'检查'的额外资格

我目前正在使用方言 C++98 和库 libc++。Xcode 设置为将源代码编译为 Objective-C++,它负责处理大多数其他错误。

I can't think of anything else relevant to this issue, it's had me stumped for hours, so any type of help is much appreciated.

我想不出与此问题相关的任何其他内容,这让我难倒了好几个小时,因此非常感谢任何类型的帮助。

采纳答案by jstevenco

Don't know your exact setup, but there have been historicalreportswhen source code references AssertMacros.hand also has some definition of a checkmethod. In my test code:

不知道你的确切设置,但是在源代码引用时有历史报告AssertMacros.h并且也有一些check方法的定义。在我的测试代码中:

#include <stdio.h>
#include <AssertMacros.h>

class InverseSumSquaredError {
public:
   void check(void) const;
}

I observed the same error. Including the line:

我观察到同样的错误。包括该行:

#define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0

prior to including AssertMacros.hfixes the issue.

在包含之前AssertMacros.h修复了问题。