2012-09-08 69 views
0

我新的目标C,我是编程的C++ ,现在我不知道如何使用@property ... 以及何时使用它 我红了很多关于这一点,我不明白产权问题

现在我试图在C++中做了它的项目,并试图输入目标C方式

我试图让(跳棋游戏) 并有2班 1局 2- Cell ... This is the Cell Class.h

#import <Foundation/Foundation.h> 

@interface Cell : NSObject 

{ 
    int number; 
    char checker; 
} 
@end 

而在板Class.h

#import <Foundation/Foundation.h> 
#import "Cell.h" 
//I dont know use it or not :S the @class 
//@class Cell; 

@interface Board : Cell 
{ 
    //is the definition right ? 
    Cell *DrawCell[64]; 

} 

,当我在board.m键入

[ DrawCell [i] checker] = 'X' ; 

它给出了这样的错误:
指派给客观的 '只读' 返回结果-C消息不允许

虽然我键入

@property (nonatomic) int number ; 
@property (nonatomic) char checker; 

,我试图将它们合成 但它也显示了这个错误

请解释做什么,为什么做,

感谢:-)

+0

必须使用getter和setter方法。现在你试图使用你的getter来返回字段,但是它没有返回字段,它返回了值,然后你试图给一个匿名返回值赋值。 – awiebe

回答

1

你要什么时候做用途:

[DrawCell [i] setChecker:'X'] 

DrawCell[i].checker = 'X' 

调用像你一样是相同的C++做

DrawCell[i].GetChecker() = 'X' 

,这一定义

class Cell { 
    public: 
    char GetChecker() { return _checker; } 
    void SetChecker(char newVal) { _checker = newVal; } 
    private: 
    char _checker; 
}