Educn 155 c x beijing university of posts

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 换到B* 如果B是protected基类,那么它的public和 protected成员只能由D的成员函数和友元、以及由D 派生出的类的成员函数和友元访问。只有D的成员和友 元以及由D派生出的类的成员和友元能将D*转换到B* 如果B是public基类,那么它的public成员可以由任何 函数使用,此外,它的protected成员能由D的成员函 数和友元,以及由D派生出的类的成员函数和友元访 问,任何函数都能将D*转换到B* Beijing University of Posts & Telecommunications Beijing [email protected] 15.3.2.1 多重继承和访问控制 在一个派生类的继承层次中,如果一个名字或者基 类可以从多条路径到达,那么若有一条路径使它能 够访问,它就是可访问的 struct B{ int m; static int sm; }; class D1:public virtual B{/*...*/}; class D2:public virtual B{/*...*/}; class DD:public D1, private D2{/*...*/}; DD* pd = new DD; B* pb = pd; // 可以:通过D1访问 int i1 = pd->m;// 可以:通过D1访问 Beijing University of Posts & Telecommunications Beijing [email protected] 多重继承和访问控制示例 如果一个实体可以通过多条途径到达,我们 还是可能无歧义地引用它 struct B{ int m; static int sm; }; class X1:public B{/*...*/}; class X2:public B{/*...*/}; class XX:public X1,public X2{/*...*/}; XX* pxx = new XX; int i1 = pxx->m; // 错误:歧义 int i2 = pxx->sm; // 可以:在XX里只有B::sm Beijing University of Posts & Telecommunications Beijing [email protected] 15.3.2.2...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern