liyuxia713

蹒跚前行者

常用链接

统计

Algorithms

C++

最新评论

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

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

posted on 2009-03-22 19:26 幸运草 阅读(720) 评论(0)  编辑 收藏 引用 所属分类: C++


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理