• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Simple C++/Obj-C question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Simple C++/Obj-C question, solved
      • From: Daniel Aarno <email@hidden>
  • Prev by Date: Re: Why multi-threading ?
  • Next by Date: Re: OmniNetworking and communicating with the main thread
  • Previous by thread: Re: Simple C++/Obj-C question
  • Next by thread: Re: Simple C++/Obj-C question, solved
  • Index(es):
    • Date
    • Thread