Compiler messages with pub/prot/priv inheritance

Discussion in 'C++' started by Edd, Jan 6, 2006.

  1. Edd

    Edd Guest

    Hello all,

    Please consider:


    class Base {
    public: int pub;
    protected: int prot;
    private: int priv;
    };

    class D1 : public Base { };
    class D2 : protected Base { };
    class D3 : private Base { };

    int main()
    {
    D1 d1; D2 d2; D3 d3;

    d1.pub = 0; //fine - public
    d1.prot = 0; //error - protected
    d1.priv = 0; //error - private

    d2.pub = 0; //error - protected
    d2.prot = 0; //error - protected? ('inaccessible')
    d2.priv = 0; //error - private

    d3.pub = 0; //error - private? ('inaccessible')
    d3.prot = 0; //error - protected
    d3.priv = 0; //error - private

    return 0;
    }


    I would have expected that the error messages for the lines I've tagged with
    'inaccessible' to complain about d2.prot being protected and d3.pub being
    private, as to my knowledge this is how they would act given their access
    specifiers and the types of inheritance used.

    However, both MinGW's g++ and VC++ Express 05 use the phrase "inaccessible" and
    avoid "protected" and "private" (which are used in all the other erroneous
    cases). Does this mean there's some kind of technical middle-ground between
    public/protected/private or am I reading in to these error messages too much?! I
    suspect the latter, but I just want to make sure.

    Thanks for your patience, and happy new year.

    Edd

    --
    Edd Dawson www.nunswithguns.net | "It's sad when someone you know
    To email me, cut the crap. | becomes someone you knew."
    | - Henry Rollins
     
    Edd, Jan 6, 2006
    #1
    1. Advertising

  2. Edd

    Mike Wahler Guest

    "Edd" <> wrote in message
    news:dpkepo$oa3$...
    > Hello all,
    >
    > Please consider:
    >
    >
    > class Base {
    > public: int pub;
    > protected: int prot;
    > private: int priv;
    > };
    >
    > class D1 : public Base { };
    > class D2 : protected Base { };
    > class D3 : private Base { };
    >
    > int main()
    > {
    > D1 d1; D2 d2; D3 d3;
    >
    > d1.pub = 0; //fine - public
    > d1.prot = 0; //error - protected
    > d1.priv = 0; //error - private
    >
    > d2.pub = 0; //error - protected
    > d2.prot = 0; //error - protected? ('inaccessible')
    > d2.priv = 0; //error - private
    >
    > d3.pub = 0; //error - private? ('inaccessible')
    > d3.prot = 0; //error - protected
    > d3.priv = 0; //error - private
    >
    > return 0;
    > }
    >
    >
    > I would have expected that the error messages for the lines I've tagged
    > with 'inaccessible' to complain about d2.prot being protected and d3.pub
    > being private, as to my knowledge this is how they would act given their
    > access specifiers and the types of inheritance used.
    >
    > However, both MinGW's g++ and VC++ Express 05 use the phrase
    > "inaccessible" and avoid "protected" and "private" (which are used in all
    > the other erroneous cases). Does this mean there's some kind of technical
    > middle-ground between public/protected/private


    No.

    > or am I reading in to these error messages too much?!



    Absolutely. The standard cites circumstances (e.g. syntax
    error) where a 'diagnostic' is required. There are absolutely
    no rules governing what the text of such messages should be.

    IOW a compiler can be considered conformant if, for any
    kind of diagnostic-required error, it emits "Wrong!" and
    nothing else. (Of course such a compiler would not last
    long in the marketplace).

    > I suspect the latter, but I just want to make sure.


    Now you are. :)

    Because of the way compilers work, it can sometimes be
    difficult to relate a given error message to a specific
    construct.

    This is solved via experience (with that
    particular compiler).

    e.g.
    -Mike
     
    Mike Wahler, Jan 6, 2006
    #2
    1. Advertising

  3. Edd

    Edd Guest

    Mike Wahler wrote:

    > Now you are. :)
    >
    > Because of the way compilers work, it can sometimes be
    > difficult to relate a given error message to a specific
    > construct.


    This is what I suspected, thanks Mike. I can sleep easy now!

    Edd


    --
    Edd Dawson www.nunswithguns.net | "It's sad when someone you know
    To email me, cut the crap. | becomes someone you knew."
    | - Henry Rollins
     
    Edd, Jan 6, 2006
    #3
    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. Replies:
    3
    Views:
    618
  2. B.W.

    Adding Pub any other way?

    B.W., Oct 3, 2003, in forum: HTML
    Replies:
    3
    Views:
    338
    Jukka K. Korpela
    Oct 3, 2003
  3. Simon Wittber
    Replies:
    0
    Views:
    216
    Simon Wittber
    Aug 17, 2007
  4. Mike Hjorleifsson

    Paramiko SFTP autologon using id_dsa.pub

    Mike Hjorleifsson, Feb 6, 2008, in forum: Python
    Replies:
    7
    Views:
    841
    Michele Hjorleifsson
    Feb 14, 2008
  5. k2
    Replies:
    0
    Views:
    220
Loading...

Share This Page