Topic: Proposal: extending "using


Author: ramnivas@rti.com (Ramnivas Laddad)
Date: 1996/12/06
Raw View

Class without virtual destructor cannot be used as publicly
inherited base class without possible misuse.

template <class T>
class myvector : public vector<T>
{
private:
    char* needCleanUp;
public:
    myvector();
    ~myvector() { delete needCleanUp;   }; // possibly virtual here
};

void f()
{
    vector<int>* vec = new myvector<int>;
    // ... use vec
    delete vec; // ~vector<int>() called.. who cleans needCleanUp
}

I am _NOT_ suggesting STL's classes should have virtual destructor
(that may not fit into STL's philosophy). Yes, I can use private
inheritence and delegation to memeber of type to be extended to
disallow,

vector<int>* vec = new myvector<int>;

But that also needs exporting all the public methods to get same
functionality of base (and that added by derived).

template <class T>
class myvector : private vector<T>
{
public:
    myvector();
    ~myvector();    // possibly virtual here

// export section
public:
    using vector<T>::insert;
    using vector<T>::erase;
    using vector<T>::begin;
    // .......

// additional methods...
// ...
};

I did the above way and every time wished there was simpler way to
export all methods. What I am looking for is way to express that
"do not use base class polymorphically (imposed by private
inheritence) but have all the functionality of base class (as if
it were publicly inherited)".

Currenlty, there is certain amount of work required _per_ method.
This is painful, especially for home grown classes where with
each evolvution, each derived class need to do extra work to pass
on benifits of newly added methods.

The proposal is to extend use of "using" for exporting every accessible
method in class.

class myvector: private vector<T>
{
private:
    char* needCleanUp;

public:
    myvector();
    ~myvector() { delete needCleanUp;   };

// export section
public:
    using vector<T>;    // export every function in vector<T>
};


1. Needs no extra keyword.
2. Intuitively extends use of "using" in the context of exporting.
    Just like "friend". One can say, "friend CLASS::f()" for
    exposing class members to one method of another class or say
    "friend CLASS" for exposing class members to (every method) in
    another class.

Any comments? Is there a way doing thing like this without need for
language extension?

-Ramnivas
(ramnivas@rti.com)



[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]