Topic: Member access control and complex member qualifications


Author: ank@despammed.com (Alexander Krotov)
Date: Mon, 11 Jul 2005 15:52:23 GMT
Raw View
In article <3gm2f7Fcv9geU1@individual.net> you wrote:
> Hello,
>
> Consider the code:
>
> class X  {
> private:
>    int i;
> };
>
> class Y  {
> public:
>    typedef X X;
> };
>
> void f()
> {
>    class X x;
>    x.Y::X::i = 5;  // is it legal?
> }
>
> Should a compiler diagnose that the X::i member is inaccessible here?

Yes, and it is very obvious why. Simply because it is private.

I belive you had another (not that obvious) example in mind:

class X  {
 public: // was private
    int i;
};

class Y  {
  private: // was public
     typedef ::X X; // otherwise there is violation of 3.3.6 rule (2)
};

void f()
{
    class X x;
    x.Y::X::i = 5;  // is it legal?
}

And now the question is: should the access rules be applied to names
(Y::X class name) or to named entities (global class X).
The very first few paragraphs of chapter 11 answer this question
exhaustively.

-ank

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: ikosarev@online.ru ("Ivan A. Kosarev")
Date: Tue, 7 Jun 2005 17:11:58 GMT
Raw View
Hello,

Consider the code:

class X  {
private:
    int i;
};

class Y  {
public:
    typedef X X;
};

void f()
{
    class X x;
    x.Y::X::i = 5;  // is it legal?
}

Should a compiler diagnose that the X::i member is inaccessible here?

Thanks.

--
Unicals Group -- Development Tools for OEMs
http://www.unicals.com


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: eldiener_no_spam_here@earthlink.net (Edward Diener No Spam)
Date: Tue, 7 Jun 2005 21:06:41 GMT
Raw View
Ivan A. Kosarev wrote:
> Hello,
>
> Consider the code:
>
> class X  {
> private:
>     int i;
> };
>
> class Y  {
> public:
>     typedef X X;
> };
>
> void f()
> {
>     class X x;
>     x.Y::X::i = 5;  // is it legal?
> }
>
> Should a compiler diagnose that the X::i member is inaccessible here?

Y::X is simply type X. Type X has no static member called 'i'. Did you
mean for it to be 'static int i;' instead ?

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: jdennett@acm.org (James Dennett)
Date: Wed, 8 Jun 2005 05:18:17 GMT
Raw View
Ivan A. Kosarev wrote:

> Hello,
>
> Consider the code:
>
> class X  {
> private:
>     int i;
> };
>
> class Y  {
> public:
>     typedef X X;
> };
>
> void f()
> {
>     class X x;
>     x.Y::X::i = 5;  // is it legal?
> }
>
> Should a compiler diagnose that the X::i member is inaccessible here?

Yes, as it's private within X.  What leads you to ask the question?
Y::X is just another name for X, and x.Y::X::i is just another way
to write x.i, which violates access control if written inside f().

-- James

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]