Re: Converting NSString to C++ std::string
Re: Converting NSString to C++ std::string
- Subject: Re: Converting NSString to C++ std::string
- From: "Stephen J. Butler" <email@hidden>
- Date: Sun, 10 May 2009 22:45:16 -0500
On Sat, May 9, 2009 at 7:45 AM, Andrew Wood <email@hidden> wrote:
> The controllers header file is as follows. As you can see I decalre dbhost
> as a std::string, but dont initialise it.
That is a false statement.
> The initalisation (which crashes) is done in the doLogin action method.
Nope. What happens is that Objective-C allocates your object,
including the bytes needed for dbhost, zero fills all the memory, and
then returns it from alloc. The problem is that std::string
constructor is NEVER called, yet all the bytes are there.
In your doLogin method, std::string's assignment operator is called,
not the constructor. The assignment operator then crashes because the
std::string memory was never initialized. It could be crashing for any
number of reasons. Possibly trying to dereference a NULL pointer in
the old string. Possibly the vtable for std::string doesn't exist.
Etc, etc.
That's why Michael Ash's solution will probably fix your problem:
"C++ objects do not work by default as Objective-C instance variables
because their constructors and destructors don't get called. This can
cause crashes like you're seeing and is probably the cause of your
trouble. Enable "Call C++ Default Ctors/Dtors in Objective-C" in your
build settings and see if that helps."
_______________________________________________
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