Re: Objective C++ from Objective C
Re: Objective C++ from Objective C
- Subject: Re: Objective C++ from Objective C
- From: Wayne Packard <email@hidden>
- Date: Mon, 02 Feb 2009 17:39:08 -0800
This code works for me. Can you see any fundamental difference between
it and what you have? It compiles with no error or warnings and it
logs "The list contains 1 items" when run.
//ObjCPPController.m
#import "ObjCPPController.h"
#import "SomeObjCPPClass.h"
@implementation ObjCPPController
- (IBAction) createACPPObject:(id)sender
{
SomeObjCPPClass* cppClass = [[SomeObjCPPClass alloc] init];
[cppClass release];
}
// SomeObjCPPClass.mm
#import "SomeObjCPPClass.h"
#include <list>
@implementation SomeObjCPPClass
- (id)init
{
self = [super init];
if (self)
{
std::list<int> temp;
temp.push_back(42);
NSLog(@"The list contains %d item(s)", temp.size());
}
return self;
}
On Feb 2, 2009, at 5:19 PM, James Trankelson wrote:
I guess I should have been more clear.
My Objective C++ file is named with an .mm extension. The
"sourcecode.cpp.objcpp" specification is the XCode setting that tells
the compiler how to treat the file.
jim
On Tue, Feb 3, 2009 at 2:16 AM, Wayne Packard <email@hidden>
wrote:
Hi,
The build system uses the file extension of the source file to
determine how
to treat the code in the file. .m files get treated as Objective-C
(by
default). .mm files get treated as Objective-C++. Try renaming
your source
code file from sourcecode.cpp.objcpp to sourcecode.mm and see if
you get
better results.
wp
On Feb 2, 2009, at 5:08 PM, James Trankelson wrote:
Hi,
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:
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];
}
@end
@implementation OCPP_Class
-(id) init
{
std::list<int> temp;
}
@end
When I try to compile this (with the latter compiled as
sourcecode.cpp.objcpp), the compiler complains about the reference
in
the OC_Class where I allocate my object. Something about the first
parameter being of the wrong pointer type.
While this sounds like something I might suspect with C++ trying to
send the this pointer, I have no idea how to get around this, or how
to fix it. Can anyone point me in the right direction?
Thanks.
-jim
_______________________________________________
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
_______________________________________________
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