• 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++ STL question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ STL question


  • Subject: Re: C++ STL question
  • From: "Dan Caugherty" <email@hidden>
  • Date: Wed, 12 Nov 2008 09:07:01 -0500

Thus spake Michael David Crawford:

>Well I have to ask - are you subclassing std::binary_function?

To be honest, I was just following an example straight out of (the 3rd
edition of) Stroustrup's book.
I'm not sure how you could get around using inheritance in this case,
short of re-implementing a standard library type.

>While it's perfectly *legal* to subclass a class or struct that has a
>non-virtual destructor, unless you're very careful about how you use
>it, it's also a *very* bad idea.

Hmm. IIRC, std::binary_function is just a binder; it only keeps a
reference to an instance passed in as a ctor argument. So (in theory)
no harm, no foul. But I agree, the subclassing of a base class with a
non-virtual destructor is a very lame approach at best.

>The reason is that if you call delete on an object of subclass type,
>but through a pointer of base type, then *only* the base's destructor
>will be called.  Your subclass' destructor won't be called at all!

I understand all of that. I'm puzzled as to why the STL (or at least
this implementation of it) encourages such bad behavior in this
particular case.

At least this isn't an Xcode issue. Time to go trawling the C++ newsgroups...

Thanks,
-- Dan Caugherty
 _______________________________________________
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

  • Prev by Date: Re: MallocDebug and GDB with 10.5.5
  • Next by Date: Objective-C Beautifier?
  • Previous by thread: Re: C++ STL question
  • Next by thread: XCode 3 auto-indent
  • Index(es):
    • Date
    • Thread