• 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: Converting NSString to C++ std::string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Re: Converting NSString to C++ std::string (From: Alex Curylo <email@hidden>)
 >Re: Converting NSString to C++ std::string (From: Drew Lawson <email@hidden>)
 >Re: Converting NSString to C++ std::string (From: Andrew Wood <email@hidden>)
 >Re: Converting NSString to C++ std::string (From: Andrew Wood <email@hidden>)

  • Prev by Date: Re: Garbage collector related crash
  • Next by Date: Re: Listing running process
  • Previous by thread: Re: Converting NSString to C++ std::string
  • Next by thread: NSXMLNode bug in method XMLString
  • Index(es):
    • Date
    • Thread