2

我已经看到相同错误的类似问题。在将代码重构为 Arc 后,我得到 Receiver type 'CGPointObject' 例如消息是前向声明错误。并且建议将@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"CCParallaxNode-Extras.m但根据CCParallaxNode.m你定义的@interface@implementation. 您需要将该@interface部分移出CCParallaxNode.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 回答