How to deal with forward declaration / # import in Cocoa correctly (? W480> cross C ++)?

I am trying to write this header file:

//@class AQPlayer;

//#import "AQPlayer.h"

@interface AQ_PWN_iPhoneViewController : UIViewController {

    AQPlayer* player;
}

@end

AQPlayer is a .mm file written in C ++.

I tried to make the class declaration forward, but it complains to me:

error: cannot find interface declaration for 'AQPlayer'

So I tried instead the "#import" header file, but it complains about something completely unexpected and strange. Here was an error snippet:

In the file included in

/Users/akaraphan/Desktop/SpecialTopic1/AQ_PWN_iPhone/Classes/AQPlayer.h:51,
                 from /Users/akaraphan/Desktop/SpecialTopic1/AQ_PWN_iPhone/Classes/AQ_PWN_iPhoneViewController.h:12,
                 from /Users/akaraphan/Desktop/SpecialTopic1/AQ_PWN_iPhone/Classes/AQ_PWN_iPhoneAppDelegate.m:10:
/Developer/Examples/CoreAudio/PublicUtility/CAStreamBasicDescription.h:78: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'CAStreamBasicDescription'
/Developer/Examples/CoreAudio/PublicUtility/CAStreamBasicDescription.h:230: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
/Developer/Examples/CoreAudio/PublicUtility/CAStreamBasicDescription.h:231: error: expected '=', ',', ';', 'asm' or '__attribute__' before '==' token
/Developer/Examples/CoreAudio/PublicUtility/CAStreamBasicDescription.h:233: error: expected '=', ',', ';', 'asm' or '__attribute__' before '!=' token
/Developer/Examples/CoreAudio/PublicUtility/CAStreamBasicDescription.h:234: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<=' token
/Developer/Examples/CoreAudio/PublicUtility/CAStreamBasicDescription.h:235: error: expected '=', ',', ';', 'asm' or '__attribute__' before '>=' token
/Developer/Examples/CoreAudio/PublicUtility/CAStreamBasicDescription.h:236: error: expected '=', ',', ';', 'asm' or '__attribute__' before '>' token
/Developer/Examples/CoreAudio/PublicUtility/CAStreamBasicDescription.h:239: error: expected ';', ',' or ')' before '&' token

Am I missing something? Can I make a declaration for this?

+3
source share
4 answers

The usual way to do this is:

// In your .h file...
@class AQPlayer;
@interface AQ_PWN_iPhoneViewController : UIViewController {
    AQPlayer *player;
}
@end

// In your .mm file (see below why it has to be .mm instead of .m)...
#import "AQ_PWN_iPhoneViewController.h"
#import "AQPlayer.h"
@implementation AQ_PWN_iPhoneViewController
...
@end

, , , AQPlayer.h Objective-C Objective-C ++. , .mm , AQPlayer, ++.

+3

AQ_PWN_iPhoneViewController .mm. , .

: : "AQPlayer", , / AQPlayer. :

- (void)viewDidLoad {

CFStringRef ref = (CFStringRef)[NSTemporaryDirectory() stringByAppendingPathComponent: @"1.mp3"];
player = new AQPlayer(&ref);

OSStatus result = player->StartQueue(false);

if (result == noErr)
    [[NSNotificationCenter defaultCenter] postNotificationName:@"playbackQueueResumed" object:self];

} >

, StartQueue, , !

+1

​​ ( ++ AQPlayer Apple SpeakHere).

, objective-c ++ objective-c ( ). , m, mm 'getInfo', "sourcecode.cpp.objcpp"

+1

-, , ++ (, ++!). , .mm(.h ). - 'sourcecode.cpp.objcpp', Atomoil.

Also, if you want a forward declaration for the C ++ class, you use the "AQPlayer class;" rather than the "@class AQPlayer;". If you do this, you’ll receive the error message “Unable to find interface declaration for XXX”.

I usually include C ++ files in an .h file, eliminating the need for a direct declaration, although sometimes you do not want to do this.

0
source

Source: https://habr.com/ru/post/1713237/


All Articles