protected inheritance modifier

Discussion in 'C++' started by Wenjie, Jul 21, 2003.

  1. Wenjie

    Wenjie Guest

    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?
    Wenjie, Jul 21, 2003
    #1
    1. Advertising

  2. 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.
    Gianni Mariani, Jul 21, 2003
    #2
    1. Advertising

  3. Wenjie

    stephan beal Guest

    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.
    stephan beal, Jul 21, 2003
    #3
  4. "stephan beal" <> 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
    Victor Bazarov, Jul 21, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    2
    Views:
    556
    Andreas Klemt
    Jul 5, 2003
  2. Stephen

    Protected access modifier in Struct

    Stephen, Apr 6, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    398
    Stephen
    Apr 7, 2006
  3. maxw_cc
    Replies:
    1
    Views:
    3,135
    Martijn van Steenbergen
    Dec 21, 2003
  4. AIK
    Replies:
    2
    Views:
    357
    Rogan Dawes
    Aug 18, 2004
  5. Pradeep Kumar

    Protected access modifier working ???

    Pradeep Kumar, May 21, 2004, in forum: C++
    Replies:
    4
    Views:
    507
    David Harmon
    May 21, 2004
Loading...

Share This Page