我想要做的事很简单,但我可能有语法错误。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