Alex Fish
Alex Fish

Reputation: 778

Xcode doesn't recognize the word "class"

I'm trying to create a simple c++ class in Xcode.

i'm just typing:

class Sculpture {

...

};

and it doesn't let me do it, I get two errors:

Unknown type name 'class'; did you mean 'Class'?

Expected ';' after top level declarator

Both on the same line of the class declaration.

i've tried to make a new file and it did not help.

the most strange part is that i have another 2-3 c++ classes working just fine

but they where not created by me so i'm not sure what are the differences.

Did anyone see something like that before?

Upvotes: 2

Views: 2716

Answers (2)

Tutankhamen
Tutankhamen

Reputation: 3562

I suppose you declare your class in .h file which is included in non-c++ compilation unit. So, check your .h file is included only in .cpp/.cc or .mm files, not in .c or .m.

Upvotes: 4

Mike Seymour
Mike Seymour

Reputation: 254411

The most likely reason is that the source file is being compiled as C, not C++. The language is determined by file extension; make sure it's .cc, .cpp or .cxx for plain C++, or .mm for Objective C++.

Upvotes: 2

Related Questions