• 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: C++ std::string tries to free() a not allocated pointer ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ std::string tries to free() a not allocated pointer ?


  • Subject: Re: C++ std::string tries to free() a not allocated pointer ?
  • From: Howard Moon <email@hidden>
  • Date: Thu, 19 Nov 2009 07:59:08 -0800


On Nov 19, 2009, at 7:48 AM, David Rowland wrote:


On Nov 19, 2009, at 7:41 AM, Howard Moon wrote:


On Nov 19, 2009, at 7:26 AM, Paul Sanders wrote:

What does your destructor do? Your copy constructors / assignment operators
appear to copy the pointer, rather than making a copy of the data pointed
to, so perhaps you end up freeing the pointer twice (once for each SQLString
object destroyed).



That would be true if realStr were a char*. But it's defined as a std::string, so its assignment operator is used, which would perform the string copy properly.



A rule of thumb with C++ is that the assignment operator, copy constructor and destructor tend to come as a package. If you need one, you often need all three.

I agree, but you missed my point. I was disagreeing with the contention that the copy constructors / assignment operators simply copied the passed pointer. They do not. The assignment here:


		const SQLString & operator=(const char * s)
		{
			realStr = s;
			return *this;
		}



... calls the std::string assignment operator to copy the string's contents to itself, because realStr is a std::string, not a char*.

-Howard


_______________________________________________ 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
References: 
 >Re: C++ std::string tries to free() a not allocated pointer ? (From: Robert Schwalbe <email@hidden>)
 >Re: C++ std::string tries to free() a not allocated pointer ? (From: Jean-Denis Muys <email@hidden>)
 >Re: C++ std::string tries to free() a not allocated pointer ? (From: "Paul Sanders" <email@hidden>)
 >Re: C++ std::string tries to free() a not allocated pointer ? (From: Howard Moon <email@hidden>)
 >Re: C++ std::string tries to free() a not allocated pointer ? (From: David Rowland <email@hidden>)

  • Prev by Date: Re: C++ std::string tries to free() a not allocated pointer ?
  • Next by Date: Re: C++ std::string tries to free() a not allocated pointer ?
  • Previous by thread: Re: C++ std::string tries to free() a not allocated pointer ?
  • Next by thread: Re: C++ std::string tries to free() a not allocated pointer ?
  • Index(es):
    • Date
    • Thread