Xcode gives syntax error in cpp code
I am trying to reuse Apple Speak Here sample code in my own iPhone app. I downloaded and compiled the project with no problem, so I added some files to my application. When I try to compile my application, the compiler gives me
MeterTable.h: 54: error: syntax error before "MeterTable"
Relevant code:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
class MeterTable // line 54
{
public:
It looks like xcode doesn't recognize MeterTable.h and MeterTable.mm as C ++ files. I checked file -> GetInfo for MeterTable.mm and it lists filetype as sourcecode.cpp.cpp.
Why doesn't it compile?
0
a source to share
3 answers
- You include "MeterTable.h" in a non-C ++ file other than MasterTable.mm.
- The error is not in 'MeterTable.h', but in the header included before it. Please note that
<stdlib.h>
... may be noop if enabled earlier.
If you want your file to be compiled with C ++, you can add this code to the top of MasterTable.mm:
#ifdef __cplusplus
#error "compiled as C++"
#else
#error "compiled as C"
#endif
+1
a source to share
Follow these steps and then try:
- Go to build setup and search for "Compile Sources As"
- Select "According to file type"
- If you include a CPP file in any of the Objective C classes, then its implementation class must be .mm, just change its extension to .mm from.m.
- Remember that even if you use CPP code hierarchically, you need to change the extension to .mm.
+3
a source to share