Unknown class type name; did you mean "class"?

I am trying to implement the AQRecorder.h class from the Apple SpeakHere Apple Xcode sample project, but even I will rename my implementation class to ext. *.mm and put the line with #import "AQRecorder.h" , still getting the error "Unknown type name 'class'; did you mean 'Class'?" and many others. Which for me means that it is not recognized as a C ++ class.

Any help would be appreciated.

+49
c ++ objective-c ios5
Dec 21 '11 at 10:58
source share
12 answers

I had this exact problem. I had a view controller using the AQRecorder class from AQRecorder.mm.

When I included AQRecorder.h in my controller, these errors occurred. It seemed to me because my direct objective-c view controller (named as a .m file) included C ++ header files that the compiler generated false errors.

There are two solutions. The fastest is to rename the view controller class, including AQRecorder.h, to a .mm file, in my case, a UIRecorderViewController from .m to .mm.

Or, move the following:

 #include "CAStreamBasicDescription.h" #include "CAXException.h" 

From AQRecorder.h to AQRecorder.mm. This means that direct C ++ style header files will no longer be included (by reference) in your simple Obj-C source.

Hope this helps and makes sense.

+46
Mar 09 '12 at 11:56
source share

In my case, this error was caused by cyclic "Import" operations in two classes: the header file for each class included the header of another class, resulting in the name of the Unknown type "ClassA"; did you mean "ClassB"? Mistake:

enter image description here

This is how my import instructions were set up when I received this error. In ClassA.h :

 Import "ClassB.h" 

In ClassB.h :

 Import "ClassA.h" 

To fix this, I used the declaration directive @class forward-declare ClassA in ClassB.h (this promises a preliminary compiler that ClassA is a valid class and that it will be available at compile time). For example:

In ClassA.h :

 Import "ClassB.h" 

In ClassB.h :

 @class ClassA; 

This fixed an error of type “ClassA” of an unknown type, but also introduced a new error: ClassB.m : The receiver type “ClassA” for the instance message is a forward declaration. For example:

enter image description here

To fix this new error, I had to import ClassA.h at the beginning of the ClassB implementation file ( ClassB.m ). Both errors are now resolved, and I get zero errors and warnings.

For example, now I have:

In ClassA.h :

 Import "ClassB.h" 

In ClassB.h :

 @class ClassA; 

In ClassB.m :

 Import "ClassA.h" 

Both error messages are now resolved.

+22
Mar 02 2018-12-21T00:
source share

I met the same mistake with you, I hope that my solution can help you. The Xcode compiler could compile objective-c and C ++ into a "* .mm" file, so you can change all of your file names that import "AQRecorder.h" (all direct and indirect) files with the ".mm" postfix. But you cannot do this, you may find that the relationship between SpeakHereController and SpeakHereViewController is somewhat complicated, I just found out how he used it, which create the SpeakHereController object in the nib file, so you don’t need to import “AQRecorder.h” in the SpeakHereViewController file . my english is stupid, i hope my answer can help you.

+8
Feb 14 2018-12-12T00:
source share

IMPORTANT: select the option "Compile source as" in the compiler settings and set its value to "Objective-C ++".

+3
Sep 27 '13 at 0:13
source share

It seems that this problem cannot be solved. If #include "my ++. H" can be shifted to the * .mm file, then it works. But if you need to use it from the objectiveC.h file, it fails. I think this is a mistake from the apple. There is a way to specify * .mm instead of * .m but nothing looks like * .hh instead of * .h

+2
Apr 29 '12 at 10:53
source share

I fixed this issue today. If you are #include or #import a C ++ * .h file or a mixed * .h C ++ / OC file in YourHeader.h, you MUST have your YourHeader.mm file. If not, then all of your C ++ files and the mixed C ++ / OC file will display compilation errors.

+1
Mar 07 '13 at 3:30
source share

Using Xcode, you can use the “language” of Objective-C ++, which allows you to mix Objective-C and C ++.

0
Dec 21 '11 at 11:09
source share

My solution may seem ridiculous, but in xcode 4.2,

To add Apple Audio sample codes, I moved all the files individually, and it works like a charm!

I do not mean dragging and dropping the entire folder, drag all the individual files one by one into the spesific folder.

0
Jan 28 2018-12-21T00:
source share

I solved this problem as follows:

Files were originally placed inside the project, but not inside the correct file structure.

YES, I know this is not an actual structre, as it is only for visual problems, but when I moved the header and CPP file to the PROJ folder, everything worked.

0
Dec 12
source share

This issue can be resolved by changing the following build settings:

Apple LLVM Compiler 4.2 - Language

C ++ language dialect (Gnu ++ 11 works for me) C ++ Standard Library (LibC ++ works for me)

You must also specify .m files as .mm if you allow Xcode to use the file extension to decide how to compile each file.

0
Aug 29 '13 at 4:48 on
source share

From my own experience, care should be taken to ensure that things are done.

  • Select the "Compile source as" option in the compiler settings and set its value to "Objective-C ++", that is, "Build Settings" → "Apple LLVM 5.1" - "Language" → "Compile Source As" - <Objective- C ++ (in Xcode 5.1.1)

  • Change the appropriate files that contain the C ++ header file from .m to .mm (sometimes you need to change all .m to .mm). This was answered by @Diziet.

  • If you encounter incompatible type errors, explicitly enter the cast type of the desired type. These errors may not appear when it was a .m file.

0
Apr 29 '14 at 7:36 on
source share

This is one of the common mistakes: Circular dependencies .

Consider an example:

File: Bh

 #import "Ah" 

File: Ah

 #import "Ch" 

File: Ch

 #import "Bh" 

This introduces a cyclic dependency.

Just override in Ch as:

 @class B; 
0
Jun 27 '14 at 9:32
source share



All Articles