Re: Deriving from vector

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Sat, 4 Aug 2007 20:06:00 -0700, Mick <Mick@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:

Do you mean derive a new template class privately from std::vector and then
define our own 'erase' type function?

That would be one way to do it. The other would be to create a new class
that has a vector member variable. Since vector has no virtual functions,
this use of private inheritance can be regarded as containment. Its main
advantage over the member variable approach is that you can use
using-declarations to redeclare some base class member functions in the
derived class. Otherwise, you have to write forwarding functions.
Using-declarations don't work at all for ctors or properly for assignment
operators, and I pretty much gave up on private inheritance a long time
ago. Now I use member variables for this sort of thing, and I never have to
worry about virtual functions. (Did you know that a derived class can
_always_ override virtual functions belonging to any of its bases?)

And since we're talking about templates, inheritance is even more
complicated when one class template derives from another. You can't just
say f() in the derived class to call a base class member function f(). You
need to write this->f() or otherwise qualify functions that aren't
"dependent" on a template parameter. (At least you need to in conforming
compilers; this remains one of the few areas in the standard (two-phase
lookup) VC++ hasn't yet implemented.)

--
Doug Harrison
Visual C++ MVP
.



Relevant Pages

  • How to hide base class member variable in derived class (w/o shadows)?
    ... I have a base class that has some member variables I do not want to be ... inherited or visible by any instance of that derived class. ... Inherits cBase ...
    (microsoft.public.dotnet.languages.vb)
  • operator= for derived class
    ... I'm having a problem with a derived class. ... the object but it does not seem to be copying the members of the base class. ... I have a class that is derived fom Cwnd, ... it copied the member variables of the derived class, but it did not also copy ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Cannot add new to a empty table by using IADORecordBinding interfa
    ... adFldOk between calling pInterface->AddNewand ... Also it helps if all your member variables are ... equivalent to 0 in the constructor of the derived class from ...
    (microsoft.public.data.ado)