C++编程(D)

Educn 155 c x beijing university of posts

Info iconThis 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 young@buptnet.edu.cn 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 young@buptnet.edu.cn 多重继承和访问控制示例 如果一个实体可以通过多条途径到达,我们 还是可能无歧义地引用它 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 young@buptnet.edu.cn 15.3.2.2...
View Full Document

This note was uploaded on 02/10/2014 for the course ECE C++ taught by Professor Xiaoshengtang during the Fall '13 term at BUPT.

Ask a homework question - tutors are online