Xcode 编译 C++ 时出错预期的成员名称或“;”声明说明符之后
Xcode error compiling c++ Expected member name or ';' after declaration specifiers
我尝试在 Xcode 中编译的 C++ 库 (openNN) 中的检查方法有问题。我将使用其中一种方法的示例,因为我怀疑它们都是由同一问题引起的。
Header 出现错误的声明:
预期成员名称或“;”在声明说明符之后。
void check(void) const;
函数定义:
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
}
如果我将 header 中的定义更改为
void InverseSumSquaredError::check(void) const;
我最终遇到错误:
会员额外资格'check'
我目前正在使用方言 C++98 和库 libc++。
Xcode 设置为将源代码编译为 Objective-C++,它会处理大多数其他错误。
我想不出与此问题相关的任何其他内容,它让我困惑了几个小时,因此非常感谢任何类型的帮助。
不知道您的确切设置,但有 historical reports 源代码引用 AssertMacros.h
并且还有一些 check
方法的定义。在我的测试代码中:
#include <stdio.h>
#include <AssertMacros.h>
class InverseSumSquaredError {
public:
void check(void) const;
}
我观察到同样的错误。包括行:
#define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
在包含 AssertMacros.h
之前解决了这个问题。
我尝试在 Xcode 中编译的 C++ 库 (openNN) 中的检查方法有问题。我将使用其中一种方法的示例,因为我怀疑它们都是由同一问题引起的。
Header 出现错误的声明:
预期成员名称或“;”在声明说明符之后。
void check(void) const;
函数定义:
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
}
如果我将 header 中的定义更改为
void InverseSumSquaredError::check(void) const;
我最终遇到错误:
会员额外资格'check'
我目前正在使用方言 C++98 和库 libc++。
Xcode 设置为将源代码编译为 Objective-C++,它会处理大多数其他错误。
我想不出与此问题相关的任何其他内容,它让我困惑了几个小时,因此非常感谢任何类型的帮助。
不知道您的确切设置,但有 historical reports 源代码引用 AssertMacros.h
并且还有一些 check
方法的定义。在我的测试代码中:
#include <stdio.h>
#include <AssertMacros.h>
class InverseSumSquaredError {
public:
void check(void) const;
}
我观察到同样的错误。包括行:
#define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
在包含 AssertMacros.h
之前解决了这个问题。