Re: Inheritance from template problem

Discussion in 'C++' started by Balog Pal, Jun 3, 2012.

  1. Balog Pal

    Balog Pal Guest

    "DSF" <>
    > Seriously, when I compile the following code, I get the error: "B::i
    > is not accessible" on the line "f = Tptr->i".


    Yep. Just followinfg the rules.

    i is protected member of class B. Why do you think it could be seen from
    class D that is not derived from B?

    > It compiles fine if "i" is made public.


    Yep.

    > I assume it has something to do with the declaration
    > of class "D".
    > I tried class "D : public A<B>, public B" with the same results.


    If you add that you can write
    f = i;

    However Tptr->i is still not accessible as it is not part of the base class
    you inherited but an unrelated instance.

    If you really like you can hack around using a pointer-to-member, but I'd
    suggest you to forget 'protected' entirely and make a clean public
    interface.
     
    Balog Pal, Jun 3, 2012
    #1
    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. Chris Theis
    Replies:
    2
    Views:
    494
    Chris Theis
    Jul 24, 2003
  2. tom_usenet
    Replies:
    0
    Views:
    560
    tom_usenet
    Jul 24, 2003
  3. Replies:
    1
    Views:
    2,141
    Gianni Mariani
    Jun 8, 2007
  4. Peng Yu
    Replies:
    3
    Views:
    801
    Thomas J. Gritzan
    Oct 26, 2008
  5. nguillot
    Replies:
    5
    Views:
    550
Loading...

Share This Page