6

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.

Adrian
  • 14,931
  • 9
  • 45
  • 70
user1899201
  • 123
  • 1
  • 1
  • 8
  • this is not 'c' so please remove the 'c' tag – user3629249 Jul 27 '15 at 23:43
  • is this going to be used as pure C++? or do you want to use mixed-mode for OSX/iOS/Cocoa purposes? – jstevenco Jul 28 '15 at 00:20
  • It's going to be mixed with Objective-c on OS X, possibly iOS – user1899201 Jul 28 '15 at 00:33
  • Does it help if you change the function name? Maybe `check` is #defined somewhere. Also, can you show a few lines before the header declaration, you could be missing a semicolon – The Dark Jul 28 '15 at 00:48
  • `check` doesn't seem to be defined elsewhere. Although after changing it it compiles fine. I guess Xcode doesn't like the method name. – user1899201 Jul 28 '15 at 00:53
  • @user1899201-- does seem to be an issue for some -- see http://stackoverflow.com/questions/16766843/using-boost-from-xcode-4-6-1-what-are-the-proper-build-settings and https://github.com/USCiLab/cereal/issues/104 -- you might try using the #define approach described in the second link. HTH. – jstevenco Jul 28 '15 at 01:10

1 Answers1

6

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.

Community
  • 1
  • 1
jstevenco
  • 2,913
  • 2
  • 25
  • 36
  • 3
    I found that with OpenCV 3, swapping the order of the header includes so that opencv2/opencv.hpp was included before any Cocoa headers also avoids the compiler error. – MoDJ Dec 31 '15 at 03:59
  • Had the same issue with different combinations of headers. – JE42 Jul 06 '16 at 13:45
  • Using `#undef check` before including `opencv.hpp` can resolve the error. This is useful in a mixed Swift/obj-C environment where you can't always shuffle the order of includes. – acj Aug 24 '16 at 14:07