Attn to All. Problem with Access Modifier.

This is the code sample
class A
{
public:
int a;
};

class B : public A
{
private:
A :: a;
};

int main()
{
B b;
b.a = 10;
cout << b.a << endl;

return 0;
}
Now, Can anyone tell me why this compiles with no problem on Linux Mandrake8.0 using g++ v. 2.95.3.
It gives me errors on Visual C++.

Compiling...
error C2248: 'a' : cannot access private member
error C2248: 'a' : cannot access private member
Error executing cl.exe.
Thanks.


Comments

  • [b][red]This message was edited by abc at 2002-9-27 18:23:18[/red][/b][hr]
    : This is the code sample
    : class A
    : {
    : public:
    : int a;
    : };
    :
    : class B : public A
    : {
    : private:
    : A :: a;
    : };
    :
    : int main()
    : {
    : B b;
    : b.a = 10;
    : cout << b.a << endl;
    :
    : return 0;
    : }
    : Now, Can anyone tell me why this compiles with no problem on Linux Mandrake8.0 using g++ v. 2.95.3.
    : It gives me errors on Visual C++.
    :
    : Compiling...
    : error C2248: 'a' : cannot access private member
    : error C2248: 'a' : cannot access private member
    : Error executing cl.exe.
    : Thanks.

    The C++ standard seems to regard [blue]access declarations[/blue] as extending rather than restricting access. It doesn't say so explicitly, but judging from the fact that they are defined to be equivalent to [blue]using[/blue] declarations ... anyway, restricting the access is done by the access specifier of the inherited base class (i.e. make that [italic]class B: private A {...}[/italic].

    see this for the standard specs:
    http://www.kuzbass.ru:8086/docs/isocpp/access.html#class.access.dcl


  • : [b][red]This message was edited by abc at 2002-9-27 18:23:18[/red][/b][hr]
    : : This is the code sample
    : : class A
    : : {
    : : public:
    : : int a;
    : : };
    : :
    : : class B : public A
    : : {
    : : private:
    : : A :: a;
    : : };
    : :
    : : int main()
    : : {
    : : B b;
    : : b.a = 10;
    : : cout << b.a << endl;
    : :
    : : return 0;
    : : }
    : : Now, Can anyone tell me why this compiles with no problem on Linux Mandrake8.0 using g++ v. 2.95.3.
    : : It gives me errors on Visual C++.
    : :
    : : Compiling...
    : : error C2248: 'a' : cannot access private member
    : : error C2248: 'a' : cannot access private member
    : : Error executing cl.exe.
    : : Thanks.
    :
    : The C++ standard seems to regard [blue]access declarations[/blue] as extending rather than restricting access. It doesn't say so explicitly, but judging from the fact that they are defined to be equivalent to [blue]using[/blue] declarations ... anyway, restricting the access is done by the access specifier of the inherited base class (i.e. make that [italic]class B: private A {...}[/italic].
    :
    : see this for the standard specs:
    : http://www.kuzbass.ru:8086/docs/isocpp/access.html#class.access.dcl

    That and access declarations are deprecated.


    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories