2009-07-22 10 views
3

私は、このヘッダファイル記述しようとしています:Cocoa Touch(Objective-C cross C++)の前方宣言/ #importを正しく処理する方法は?

//@class AQPlayer; 

//#import "AQPlayer.h" 

@interface AQ_PWN_iPhoneViewController : UIViewController { 

    AQPlayer* player; 
} 

@end 

AQPlayerはC++で書かれた.mmファイルです。

私はここに、クラス前方宣言を作ってみましたが、それは私に文句:

error: cannot find interface declaration for 'AQPlayer'

だから私は、代わりに「の#import」にヘッダファイルを試してみましたが、それは完全にオフと奇妙な何かを不平を言います。ここでは、エラーのスライスを訴えています:ファイルで

/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 

から含ま私は何かが足りないのですか?これについて前向きに宣言することはできませんか?

答えて

3

これは次のようになります行うには、通常の方法:コンパイラは代わりのObjective-C++のObjective-CのようAQPlayer.hを解析しようとしているので、あなたが見

// 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 

ヘビーデューティーエラーがある可能性があります。特定のクラスがC++を使用していなくても、AQPlayerをインポートするすべてのソースファイルには、おそらく.mmを使用する必要があります。

1

既にAQ_PWN_iPhoneViewControllerを.mmファイルにしました。そうではない、それはそれを修正しない。

ここにいくつかの情報があります:AQPlayerインスタンスのメソッド/関数を呼び出そうとすると、エラー "エラー: 'AQPlayer'のインタフェース宣言が見つかりません。ここでは例です:StartQueueのような任意の関数呼び出しがエラーが離れて行くようになりますが、私はメソッドを呼び出す必要があります削除

- (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]; 

}

+0

元の質問を回答として投稿するのではなく、編集する必要があります。 これは、AQPlayerとしてobj-cまたはC++クラスですか?'@class AQPlayer;を与えた前方宣言はObj-Cですが、あなたのメソッド呼び出し' player-> StartQueue(false); 'はC++の構文です。 C++では 'class AQPlayer;'、Obj-Cでは '[player startQueue:NO];が必要です。 –

1

また、まったく同じ問題(Appleの「SpeakHere」デモからAQPlayer C++クラスを再利用しようとしています)も発生していました。

コンパイラが混乱して、objective-C++をobjective-c(つまりすべてのエラー)としてコンパイルしようとしています。 mmファイルをインポートして「getInfo」を選択し、次にファイルタイプを「sourcecode.cpp.objcpp」に変更するmファイルを右クリックしてコンパイルすることができました。

0

まず、コンパイラにファイルにはC++コード(C++コードを含むファイルも含まれます)があります。 .mm拡張子に名前を変更することでこれを行うことができます(.hは同じままです)。 2番目の方法は、ファイルタイプを 'sourcecode.cpp.objcpp'に設定することです。

また、C++クラスの前方宣言を使用する場合は、 'class AQPlayer;'を使用し、 '@class AQPlayer;'は使用しません。もしあなたがそうした場合、「XXXのインタフェース宣言を見つけることができません」というエラーが発生します。

私は通常、.hファイルにC++ファイルを含めて、前方宣言の必要性を排除します。この。

関連する問題