Re: templates & classes
"Pete Becker" <pete@versatilecoding.com> wrote in message
news:FrSdnXYRvKafzkLYnZ2dnUVZ_vWtnZ2d@giganews.com
Fei Liu wrote:
Pete Becker wrote:
Fei Liu wrote:
Pete Becker wrote:
Fei Liu wrote:
The description of the OP's problem requires that 2 classes do
not share the storage of those static members. In this case,
derivation won't work.
Of course it will. The things that aren't shared don't go in the
base class.
It will what?
"In this case, derivation won't work."
"Of course it will.
What, specifically, do you claim "won't work"? Whatever is defined
in the base class is part of the base class, and whatever is
defined in the derived classes is part of the derived classes. So
if you want the derived classes to hold something in common, put it
in the base class. If you want the derived classes to hold
independent things, put them in the derived classes. The result is
that the derived classes both have whatever is in the base class,
and each has whatever is defined for it.
Clearly you don't understand the OP's spec, hint it's a device
driver. Your logical representation fails to meet the requirement of
the physical model.
On the contrary: I have read it carefully, and suggested an approach
that will do exactly what he said he wants.
Once again: what, specifically, do you claim "won't work"? No more
handwaving. Point out the exact problem, so that readers of this
thread will have a chance at understanding what it is that you think
can't be done through inheritance.
Speaking for myself, I didn't think much about the OP's spec, I just wanted
to answer the OP's question (just stating a fact here, not making a case).
My read was that the OP was mainly interested in code re-use. Thus the OP
didn't want identical lists of members in the derived classes. Using a
template to create two distinct bases was a way to get all those members
into the derived classes and make the static variables distinct, while only
typing them once (just why the OP wanted distinct static variables I don't
know).
--
John Carson