views:

68

answers:

2

Any ideas why Xcode wont let me define a c++ class in my cocoa project?

I am trying to use a C++ class in my cocoa project but I am getting build errors just creating the c++ header file.

class SomeClass{
public:
     int count;
};

Expected '=', ',', ';', 'asm' or 'attribute' before 'SomeClass' in .....

If I remove all code from the header file, ?the cpp file builds without any errors and is included in the list of compiled sources...

+4  A: 

I think you need to add a semicolon:

class SomeClass{
public:
     int count;
};
PeterK
+5  A: 

Ensure that your Objective-C source files have the .mm extension so that they are treated as Objective-C++ files (there are other ways of getting Xcode to treat your files as Objective-C++ source even if they don't have the .mm extension, but it is easier just to use the .mm extension), and also follow PeterK's advice about appending a semicolon after the class declaration.

dreamlax