user1899201
user1899201

Reputation: 123

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

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.

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.

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.

Upvotes: 6

Views: 21596

Answers (1)

jstevenco
jstevenco

Reputation: 2953

Don't know your exact setup, but there have been historical reports when source code references AssertMacros.h and also has some definition of a check method. In my test code:

#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.h fixes the issue.

Upvotes: 6

Related Questions