Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > protected inheritance modifier

Reply
Thread Tools

protected inheritance modifier

 
 
Wenjie
Guest
Posts: n/a
 
      07-21-2003
Hello!


Suppose I have:

class B {
protected:
virtual ~B();
};

class D: public B {
public:
~D();
};


Is it a good practice to use "protected" in class B?
 
Reply With Quote
 
 
 
 
Gianni Mariani
Guest
Posts: n/a
 
      07-21-2003
Wenjie wrote:
> Hello!
>
>
> Suppose I have:
>
> class B {
> protected:
> virtual ~B();
> };
>
> class D: public B {
> public:
> ~D();
> };
>
>
> Is it a good practice to use "protected" in class B?


only if you want methods in classes that inherit B be the only methods
able to delete B.

 
Reply With Quote
 
 
 
 
stephan beal
Guest
Posts: n/a
 
      07-21-2003
Wenjie wrote:
> Suppose I have:
>
> class B {
> protected:
> virtual ~B();
> };
>
> class D: public B {
> public:
> ~D();
> };
>
>
> Is it a good practice to use "protected" in class B?


Not an answer to your question, but something to keep i mind:
Making your dtor protected will keep your class from being used in 3rd-party
custom memory-mgt code which calls the dtor directly (as in,
thefoo->~foo()).

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      07-21-2003
"stephan beal" <(E-Mail Removed)> wrote...
> Wenjie wrote:
> > Suppose I have:
> >
> > class B {
> > protected:
> > virtual ~B();
> > };
> >
> > class D: public B {
> > public:
> > ~D();
> > };
> >
> >
> > Is it a good practice to use "protected" in class B?

>
> Not an answer to your question, but something to keep i mind:
> Making your dtor protected will keep your class from being used in

3rd-party
> custom memory-mgt code which calls the dtor directly (as in,
> thefoo->~foo()).


.... or indirectly, anywhere, as in

{
foo afoo;
...
} // afoo::~foo() is supposed to be called here

Victor


 
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
Protected access modifier in Struct Stephen ASP .Net 2 04-07-2006 07:11 PM
Question about Protected Modifier AIK Java 2 08-18-2004 06:49 AM
Protected access modifier working ??? Pradeep Kumar C++ 4 05-21-2004 02:16 PM
Private access modifier and Inheritance (Inheritance implementation in Java) maxw_cc Java 1 12-21-2003 11:38 AM
Difference between "Protected WithEvents myClassName" And "Protected myClassName" ? Andreas Klemt ASP .Net 2 07-05-2003 12:51 AM



Advertisments