1.派生類對基類private成員沒有訪問權限。
2.派生類只能通過派生類對象訪問其基類的protected成員,派生類對其基類類型對象的protected成員沒有特殊訪問權限。
#include<iostream>
using namespace std;
class Base
{
public:
Base():i(0),j(0){};
protected:
int i;
private:
int j;
};
class Derived:public Base
{
Derived():Base(){};
print(const Base &b, const Derived &d)
{
int num = i;
//num = b.i; //error. cannot access protected member declared in class 'Base'
num = d.i;
//num = d.j; //error. cannot access private member declared in class 'Base'
};
};
int main()
{
return 0;
}

文章來源:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!262.entry