1

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?

4

2 回答 2

3

我想你在非 C++ 编译单元中包含的 .h 文件中声明你的类。因此,请检查您的 .h 文件是否仅包含在 .cpp/.cc 或 .mm 文件中,而不包含在 .c 或 .m 中。

于 2012-08-28T14:03:00.630 回答
2

最可能的原因是源文件被编译为 C,而不是 C++。语言由文件扩展名决定;确保它是.cc,.cpp.cxx用于普通 C++ 或.mm用于 Objective C++。

于 2012-08-28T13:57:56.653 回答