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://c.services.spaces.live.com/CollectionWebService/c.gif?cid=982263437555584821&page=RSS%ef%bc%9a%e6%b4%be%e7%94%9f%e7%b1%bb%e5%af%b9%e5%9f%ba%e7%b1%bb%e6%88%90%e5%91%98%e7%9a%84%e8%ae%bf%e9%97%ae%e6%9d%83%e9%99%90&referrer=)
![](http://c.live.com/c.gif?NC=31263&NA=1149&PI=81873&RF=&DI=3919&PS=85545&TP=liyuxia-life.spaces.live.com>1=liyuxia-life)
文章来源:http://liyuxia-life.spaces.live.com/Blog/cns!DA1B364675ACF35!262.entry