Re: Simple C++/Obj-C question
Re: Simple C++/Obj-C question
- Subject: Re: Simple C++/Obj-C question
- From: Todd Heberlein <email@hidden>
- Date: Mon, 26 May 2003 18:57:27 -0700
On Sunday, May 25, 2003, at 12:36 PM, Daniel Aarno wrote:
What am I doing wrong and how should I solve it?
Hmmm... I haven't placed with ObjC++ in a little while, so I hope my
information isn't too old.
(1) In Project Builder change all objective C files that include the
C++ header files to a .mm file (an objc++ file). This may include a
objective C file that include a header file that in turn includes a C++
header (i.e., watch out for cascading include files).
(2) After the changes, do a make clean (click the broom) before trying
to recompile.
(3) If your objective C class uses a C++ data structure, make sure the
object is a pointer and then allocate the C++ object in the appropriate
init method. For example:
/* ------------ MyController.h ---------- */
#import <Cocoa/Cocoa.h>
#import <vector>
@interface MyController : NSObject
{
IBOutlet id the_text;
std::vector<int> *p_vector; /* make sure this is a pointer */
}
- init;
- (IBAction)doButton:(id)sender;
@end
/* ------------ MyController.mm ---------- */
#import "MyController.h"
@implementation MyController
- init
{
[super init];
p_vector = new std::vector<int>; /* allocate the C++ object */
return self;
}
- (IBAction)doButton:(id)sender
{
p_vector->push_back(3); /* manipulate like regular C++ */
[the_text setIntValue: p_vector->size()];
}
@end
Todd
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.