我想要做的事很簡單,但我可能有語法錯誤。acces C++ datamember在objective-c類
我有一個Objective-C接口和Note class
參數。 Note.h是一個基本如下所示的C++類:
#include <string>
using namespace std;
class Note {
public:
string name;
Note(string name){
this->name = name; // ERROR: Cannot find interface declaration for 'Note'
}
};
這是我的控制器,它使用的是註釋。我改變文件擴展名.mm
@class Note;
@interface InstrumentGridViewController : UIViewController {
@public
Note* note;
}
@property (nonatomic, retain) Note* note;
這是我如何使用它:
@implementation InstrumentGridViewController
@synthesize note;
- (void)buttonPressed:(id)sender {
note = Note("fa"); // ERROR: Cannot convert 'Note' to 'Note*' in assignment
NSLog(@"naam van de noot is %s", note->name); // ERROR: Cannot find interface declaration for 'Note'
}
雖然(我將他們添加上的評論我得到這三個錯誤右行)
任何想法我怎麼做錯了?
...並且不要忘記刪除'buttonPressed中的舊音符:' – 2012-07-23 17:01:40
@NikolaiRuhe是的,對象的一生似乎與我不直觀... – trojanfoe 2012-07-23 17:02:24
Where or when我應該分配的對象比? 'buttonPressed'是我第一次使用它,所以我認爲我會在那裏使用它。 – networkprofile 2012-07-23 17:04:37