Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

c++ and destructors

Name: Anonymous 2006-11-17 15:51

Okay, take a peek at this code:
class A {};
class B:public A {
public:
  B() { /*stuff*/ }
  ~B() { /*stuff*/ }
};

Is this valid or do I have to declare an (empty) virtual destructor in class A? I _could_ make an app and test but that won't tell me if the result is defined or not.

Name: Anonymous 2006-11-17 16:01

~B() will destroy the B part of the object.  ~A() will destroy the A part of the object.  if the default ~A() destructor will suffice for an A object, you need not create a new one even if you inherit from it.

Name: Anonymous 2006-11-17 17:10

>>1
Look, you're dead:
A *lolwhat = new B;
delete lolwhat; // you suck, ~A() is not virtual...

Name: Anonymous 2006-11-17 17:48

>>3
Thanks Anonymous, that's what I was wondering.

Name: Anonymous 2006-11-17 18:03

>>4
this is the kind of crap that should not happen but if you fill a vector<A*> with B*...

Name: ​​​​​​​​​​ 2010-10-23 2:40

Name: Sgt.Kabu눿筋kiman㧧퍹 2012-05-28 21:16

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List