您的位置:首页 > 其它

[导入]派生类对基类成员的访问权限

2009-03-22 19:26 253 查看
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



[align=right]幸运草 2009-03-22 19:26 发表评论[/align]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐