• 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: Objective C++ from Objective C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective C++ from Objective C


  • Subject: Re: Objective C++ from Objective C
  • From: Peter N Lewis <email@hidden>
  • Date: Tue, 3 Feb 2009 10:48:22 +0900

At 2:08 +0100 3/2/09, James Trankelson wrote:
For the majority of my OS X programming life, I've been using
Objective C exclusively. However, I now have a reason to want to use
some C++ standard template libraries, and have started looking into
Objective C++. I've found the documentation on Objective C++ lacking,
and was hoping if someone could just show me how I can accomplish the
following:

Objective C is C with the added Objective C stuff.

Objective C++ is C++ with the added Objective C stuff.

In either case, the code you write between the { } is the same syntax as normal for C/C++ when referring to C/C++ stuff. When using Objective C methods, you use the [] syntax. Then there are the other Objective C additions (like property access, exceptions and syncronization, but they are less relevant to your problem I think.

 >From an Objective C class, allocate an object that can contain
references to C++ standard template libraries.

For example:

#include "OCPP_Class.h"

@implementation OC_Class

-(void) foo {
  OCPP_Class *bar = [[OCPP_Class alloc] init];
}

I suspect your problem is that OCPP_Class is a C++ class, but you are treating it as an Objective C class. The two are entirely different.


Try this:

-(void) foo {
  OCPP_Class *bar = new OCPP_Class;
}

Treat bar exactly as you would if you were writing C++ code.

I hope that helps,
   Peter.

--
              Keyboard Maestro 3 Now Available!
   Now run macros from your iPhone with Keyboard Maestro Control!

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/>           <http://download.stairways.com/>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Objective C++ from Objective C (From: James Trankelson <email@hidden>)

  • Prev by Date: Re: Objective C++ from Objective C
  • Next by Date: Re: Read lines from very large text file
  • Previous by thread: Re: Objective C++ from Objective C
  • Next by thread: Grouping separator not working in table
  • Index(es):
    • Date
    • Thread