2

同じエラーについて同様の質問を見てきました。コードを Arc にリファクタリングした後、 Receiver type 'CGPointObject' for instance message is a forward declaration error を取得します。そして、@class メソッドを宣言の .h ファイルと #import .h ファイルに移動し、{ を賢く使用することをお勧めします。

すべての推奨事項を実行しましたが、それでもエラーが発生します。

CCParallaxNode-Extras.h

#import "cocos2d.h"

@class CGPointObject;

@interface CCParallaxNode (Extras)

-(void) incrementOffset:(CGPoint)offset forChild:(CCNode*)node;

@end

CCParallaxNode-Extras.m

    #import "CCParallaxNode-Extras.h"
    #import "CCParallaxNode.h"


    @implementation CCParallaxNode(Extras)


    -(void) incrementOffset:(CGPoint)offset forChild:(CCNode*)node 
    {

        for( unsigned int i=0;i < parallaxArray_->num;i++) {
            CGPointObject *point = parallaxArray_->arr[i];
            if( [[point child] isEqual:node] ) {
                [point setOffset:ccpAdd([point offset], offset)];
                break;
            }
        }
    }

@end

クラスの定義:CCParallaxNode.m

#import "CCParallaxNode.h"
#import "Support/CGPointExtension.h"
#import "Support/ccCArray.h"

@interface CGPointObject : NSObject
{
    CGPoint ratio_;
    CGPoint offset_;
    CCNode *child_; // weak ref
}
@property (nonatomic,readwrite) CGPoint ratio;
@property (nonatomic,readwrite) CGPoint offset;
@property (nonatomic,readwrite,assign) CCNode *child;
+(id) pointWithCGPoint:(CGPoint)point offset:(CGPoint)offset;
-(id) initWithCGPoint:(CGPoint)point offset:(CGPoint)offset;
@end
@implementation CGPointObject
@synthesize ratio = ratio_;
@synthesize offset = offset_;
@synthesize child=child_;

+(id) pointWithCGPoint:(CGPoint)ratio offset:(CGPoint)offset
{
    return [[[self alloc] initWithCGPoint:ratio offset:offset] autorelease];
}
-(id) initWithCGPoint:(CGPoint)ratio offset:(CGPoint)offset
{
    if( (self=[super init])) {
        ratio_ = ratio;
        offset_ = offset;
    }
    return self;
}
@end

上記の問題を解決するにはどうすればよいですか?

4

1 に答える 1

9

#import "CCParallaxNode.h"必要なようにinを含めますが、あなたCCParallaxNode-Extras.mによれば、と のCCParallaxNode.m両方を定義しています。セクションをヘッダー ファイルとの間で移動する必要があります。@interface@implementation@interfaceCCParallaxNode.m

CCParallaxNode.h

//Add necessary includes ...

@interface CGPointObject : NSObject
{
    CGPoint ratio_;
    CGPoint offset_;
    CCNode *child_; // weak ref
}
@property (nonatomic,readwrite) CGPoint ratio;
@property (nonatomic,readwrite) CGPoint offset;
@property (nonatomic,readwrite,assign) CCNode *child;
+(id) pointWithCGPoint:(CGPoint)point offset:(CGPoint)offset;
-(id) initWithCGPoint:(CGPoint)point offset:(CGPoint)offset;
@end
于 2012-11-19T16:41:01.640 に答える