Is there any difference these two pieces of code?

Posted by Poiuyt on Stack Overflow See other posts from Stack Overflow or by Poiuyt
Published on 2010-06-13T18:31:16Z Indexed on 2010/06/13 18:42 UTC
Read the original article Hit count: 126

Filed under:
|
#include<stdio.h>

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

int main(){
    B b;
    printf("%d", b.a);
    return 0;
}

#include<stdio.h>

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

int main(){
    B b;
    printf("%d", b.a);
    return 0;
}

I ask because I get different errors:

error: 'int B::a' is private

error: 'int A::a' is inaccessible

Apart from what the errors might reveal, is there any difference at all in the behaviour of these two pieces of code?

© Stack Overflow or respective owner

Related posts about c++

Related posts about inheritance