Expected ; after top level declarator, error in xcode

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.

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

void func(int a)

XCode had actually inserted

void func(<#int a#>)

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


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

#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:

#ifndef Parser_hpp
#define Parser_hpp
#if defined __cplusplus

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

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

Tags:

C++

C

Xcode