Re: Xcode, Cocoa and std::list
Re: Xcode, Cocoa and std::list
- Subject: Re: Xcode, Cocoa and std::list
- From: Dave Carrigan <email@hidden>
- Date: Fri, 27 Mar 2009 10:39:50 -0700
On Mar 27, 2009, at 10:04 AM, McLaughlin, Michael P. wrote:
Don't know if this is the proper forum for this but I encountered a
strange
error, as follows:
In a Cocoa header for an ObjectiveC++ class, I have (after the list
and
vector headers, etc.)
@interface myClass : NSObject {
std::vector<int> myVec;
std::list<int> myList;
}
In the implementation (myClass.mm) file, myVec behaves just as
expected but
any reference to myList (e.g., myList.size()) crashes with a
BAD_ACCESS
error.
C++ members of an Objective-C class will not have their constructors
called if the C++ class has virtual methods. See
http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjectiveC/Articles/ocCPlusPlus.html
In general, I've found it safer to use pointers for all of my C++
class members. If you have a bunch of members, create a struct that
holds all the members, then add a pointer to the struct in your ObjC
class. When you allocate the struct with new, all of the struct's
members' constructors will get properly called.
--
Dave Carrigan
email@hidden
Seattle, WA, USA
Attachment:
PGP.sig
Description: This is a digitally signed message part
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden