Re: Inheriting from STL bitset

From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 11/05/04


Date: Fri, 05 Nov 2004 16:53:46 -0500

shaun roe wrote:
> I want something which is very like a bitset<64> but with a couple of
> extra functions: set/get the two 32 bit words, and conversion to
> unsigned long long.

There is no unsigned long long in C++. You must be talking about some
compiler extension you're using.

> I can do this easily by inheriting from bitset<64>, but I know that STL
> has no virtual destructor. Can I get around this by calling the
> baseclass destructor explicitly in my derived class?

You don't need to. Virtual destructor is needed when you delete an object
of derived class using a base class pointer. If you're not going to use
dynamic memory allocation, the destructor of the derived class _will_ call
the destructor of the base class.

> Is there another way to get all of the bitset<64> functionality without
> rewriting a lot of code?

Do your inheriting thing and see how it goes.

V



Relevant Pages

  • Re: My final shape program, what do you think?
    ... >> pointer to its base class then the base class must have a virtual ... >> destructor or its undefined behaviour. ... Whenever you want to delete a derived class object through a pointer to ... base, that base needs to have a virtual destructor, period. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: My final shape program, what do you think?
    ... >> pointer to its base class then the base class must have a virtual ... >> destructor or its undefined behaviour. ... Whenever you want to delete a derived class object through a pointer to ... base, that base needs to have a virtual destructor, period. ...
    (comp.lang.cpp)
  • Re: virtual destructor
    ... To get a base class pointer to call a derived class method, ... if the Derived Class constructor creates resources. ... If the base class destructor is NOT virtual, ...
    (comp.lang.cpp)
  • Re: Virtual destructors are unique virtuals right
    ... The destructor of a derived class does not call the ... >> of its base class, regardless of whether the base class has a virtual ... The derived class destructor always calls the base class ...
    (comp.lang.cpp)
  • Re: Compile time check for virtual destructor
    ... >Is there a standard way of checking for a virtual destructor? ... destructor. ... all derived destructors are also virtual. ... It is perfectly legal to derive a class from a base class which has no ...
    (comp.lang.cpp)

Loading