Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Delegation question...

Reply
Thread Tools

Delegation question...

 
 
red floyd
Guest
Posts: n/a
 
      05-26-2008
tedzhou wrote:
> On May 24, 5:19 pm, Ian Collins <ian-n...@hotmail.com> wrote:
>> James Kanze wrote:
>>> On May 24, 9:47 am, Ian Collins <ian-n...@hotmail.com> wrote:
>>> [...]
>>>> I was going to suggest that technique, but decided against it as the OP
>>>> wanted to delegate members of std::set. I wouldn't recommend deriving
>>>> from a standard container.
>>> Not even privately? I have no problems with private inheritance
>>> from a standard container; private inheritance is part of the
>>> implementation.

>> Yes, you're right, I overlooked private inheritance.

>
> Private inheritance is not suggested on standard container either.
> Because the standard containers are not designed for inheritance at
> all.


Not necessarily. Several of the standard adapter classes
(std:riority_queue for example) have protected members, which implies
that they were designed to be inherited from.
 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      05-26-2008
tedzhou wrote:

> On May 24, 5:19*pm, Ian Collins <ian-n...@hotmail.com> wrote:
>> James Kanze wrote:
>> > On May 24, 9:47 am, Ian Collins <ian-n...@hotmail.com> wrote:

>>
>> > [...]
>> >> I was going to suggest that technique, but decided against it as the
>> >> OP wanted to delegate members of std::set. *I wouldn't recommend
>> >> deriving from a standard container.

>>
>> > Not even privately? *I have no problems with private inheritance
>> > from a standard container; private inheritance is part of the
>> > implementation.

>>
>> Yes, you're right, I overlooked private inheritance.

>
> Private inheritance is not suggested on standard container either.
> Because the standard containers are not designed for inheritance at
> all.
> Just think about the polymorphism and virtual destruction , then
> you'll
> get the conclusion that inheritance from standard containors will be
> dangerous.


That argument is bogus for two reasons:

(a) As others have pointed out, private differs from public inheritance with
regard to destruction.

(b) Even with public inheritance, the argument does not hold as it would
apply equally well to std::unary_function or std::iterator, two classes
that are meant to be publicly inherited from and that lack virtual
destructors. Inheritance in C++ is not necessarily tied to polymorphism.

[Note: that you failed to point out a valid reason as to why public
inheritance from standard containers might not be such a good move, is not
to say that there are no such reasons. However, those tend to focus on
other issues rather than the lack of a virtual destructor.]


Best

Kai-Uwe Bux
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      05-27-2008
On May 26, 11:00 am, Ian Collins <ian-n...@hotmail.com> wrote:
> tedzhou wrote:
> > On May 24, 5:19 pm, Ian Collins <ian-n...@hotmail.com> wrote:
> >> James Kanze wrote:
> >>> On May 24, 9:47 am, Ian Collins <ian-n...@hotmail.com> wrote:
> >>> [...]
> >>>> I was going to suggest that technique, but decided against it as the OP
> >>>> wanted to delegate members of std::set. I wouldn't recommend deriving
> >>>> from a standard container.
> >>> Not even privately? I have no problems with private inheritance
> >>> from a standard container; private inheritance is part of the
> >>> implementation.
> >> Yes, you're right, I overlooked private inheritance.


> > Private inheritance is not suggested on standard container
> > either. Because the standard containers are not designed
> > for inheritance at all. Just think about the polymorphism
> > and virtual destruction , then you'll get the conclusion
> > that inheritance from standard containors will be dangerous.


> With public inheritance maybe, but you can't point a base* to
> a derived object if derived uses private inheritance.


You can, and in fact, one frequent use of private inheritance
involves doing just that. But you need cooperation from the
derived class to do so: if the derived class doesn't give you
the Base*, you can't get it otherwise. (The "frequent use" is
to derive privately from something like "EventHander": for
normal client code, this is an implementation detail, and they
can't consider the class to be an EventHander. But the class
itself may register itself as an EventHander with some
EventNotifier, who will address the class through an
EventHander*.)

> Private inheritance hides the fact that a derived is a base.


Except in the explicit cases where it wants to behave as a base.

None of which is really a problem when deriving privately from a
standard container, since you, the author of the class, have
total control, and of course, you will not expose the
derivation.

--
James Kanze (GABI Software) email:
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
delegation question, where I want prototype style delegation Sam Roberts Ruby 4 05-07-2008 05:48 AM
Stub Zone vs. Delegation (70-291) a_bleem_user Microsoft Certification 2 04-25-2005 07:30 PM
cross - tier event delegation ruselw@gmail.com ASP .Net 2 02-02-2005 04:00 AM
Problem with delegation from ASP.NET to SQL Kelly D. Jones ASP .Net 0 09-17-2003 07:42 PM
Problem with impersonation and delegation Kelly D. Jones ASP .Net 1 09-12-2003 04:43 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57