Topic: FAQ remarks
Author: marc@offline.be (Marc Duponcheel)
Date: 19 Jun 93 16:30:57 PST Raw View
Hi folks,
I just read the C++-FAQ and I liked it very much.
However there are a few things I would like to get some feedback on.
==============================================================================
Q69: How are `private derivation' and `containment' similar? dissimilar?
A: Private derivation can be thought of as a syntactic variant of containment
(has-a). Ex: it is NOT true that a privately derived is-a-kind-of-a Base:
With private derivation:
class Car : private Engine {/*...*/}; //a Car is NOT a-kind-of Engine
Similarly:
class Car { Engine e; /*...*/ }; //normal containment
==============================================================================
I would NOT say that private derivation ALWAYS equals containment.
e.g.
class MyRaceCar : private Citroen2PK {/*...*/}
Certainly I haven't put a Citroen2PK IN MyRaceCar.
MyRaceCar is-a-kind-of-a Citroen2PK but rather a special one that I don't
like 'derivators' to play with. In fact nobody has business about how I
turned the Citroen2PK into MyRaceCar.
==============================================================================
Q80: What is a `virtual constructor'?
Here is an example of how you could use `clone()' and `fresh()' methods:
class Set { //normally this would be a template
public:
virtual void insert(int); //Set of `int'
virtual int remove();
//...
virtual Set& clone() const = 0; //pure virtual; Set is an ABC
virtual Set& fresh() const = 0;
virtual ~Set() { } //see on `virtual destructors' for more
};
class SetHT : public Set {
//a hash table in here
public:
//...
Set& clone() const { return *new SetHT(*this); }
Set& fresh() const { return *new SetHT(); }
};
==============================================================================
I wonder who is ever going to delete s.clone() and s.fresh() ?
Is there anybody who is willing to give his brief point of view
about virtual constructors (and clone()) ? I know this is FAQ but
I am just reacting upon FAQ ...
==============================================================================
Q99: What is `virtual data', and how-can / why-would I use it in C++?
==============================================================================
I liked that one !
In fact here each new is in concert with a delete.
VStack(int cap=10) : v(*new Vec(cap)), sp(0) { } //FREESTORE
~VStack() {delete &v;} //NECESSARY
-- marc.
Author: cjg@cray.com (Chris Gennaula)
Date: 20 Jun 93 19:33:11 CDT Raw View
New person question: where is the C++ FAQ kept? Please response via email.
Thank you.
Chris Gennaula
Cray Research, Inc.
cjg@cray.com