2012-09-08 132 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; 
}