[导入]派生类对基类成员的访问权限
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
转载请注明出处: http://www.cnblogs.com/liyuxia713/