我正在尝试将SneakyInput添加到我当前的Cocos2D-x项目中。我必须调整一些东西才能使它工作(因为github源已经过时)。长话短说,一切正常,除了我从下面的代码中得到两个警告(用注释表示):
错误:
属性'readonly'属性'color'限制属性 'readwrite'继承自'CCRGBAProtocol'
的属性
#import "cocos2d.h"
@interface ColoredCircleSprite : CCNode <CCRGBAProtocol, CCBlendProtocol> {
float radius_;
GLubyte opacity_;
ccColor3B color_;
NSUInteger numberOfSegments;
GLfloat *circleVertices_;
ccBlendFunc blendFunc_;
}
@property (nonatomic,readwrite) float radius;
/** Opacity: conforms to CCRGBAProtocol protocol */
@property (nonatomic,readonly) GLubyte opacity; //<--------- ERROR thrown here!!
/** Opacity: conforms to CCRGBAProtocol protocol */
@property (nonatomic,readonly) ccColor3B color; //<--------- ERROR thrown here!!
/** BlendFunction. Conforms to CCBlendProtocol protocol */
@property (nonatomic,readwrite) ccBlendFunc blendFunc;
/** creates a Circle with color and radius */
+ (id) circleWithColor: (ccColor4B)color radius:(GLfloat)r;
/** initializes a Circle with color and radius */
- (id) initWithColor:(ccColor4B)color radius:(GLfloat)r;
- (BOOL) containsPoint:(CGPoint)point;
@end
我能找到的有关此错误的唯一信息来自here。接受的答案是:
它表示你可以将readonly属性重新声明为readwrite,但是你是 做相反的事情。你不能/不应该这样做,因为它是可能的 这样做:
Sub* s = [[[Sub alloc] init] autorelease];
Base* b = s;
b.foo = YES; //legal for `Base` objects, but not legal for `Sub` objects
我的问题是我并不完全理解维基百科的文章。我知道这个问题源于继承。来自is-a的整个A OOP B事物。等等。我只是想知道接近和解决这个问题的适当方法是什么?我是喜欢0警告/错误的人之一。是否有一个简单的方法来补救这个警告,抑制它等等?我也很欣赏一些关于“为什么”确切地说你的方法有效的解释(因为每个人,包括我自己,都可以从中学习)。