1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| #include <iostream>
//~ #include <string>
using namespace std;
class B
{
public:
virtual void foo()
{
cout<<"B::foo()"<<endl;
}
};
class D1: public virtual B //~ 公开继承
{
};
class D2: private virtual B //~ 私有继承
{
};
class S: public D1, public D2
{
};
int
main()
{
S * pS = new S;
D1 * pD1 = pS;
D2 * pD2 = pS;
pS->foo(); //~ OK, 存在一条访问路径B->D1->S
pD1->foo();
//pD2->foo(); //~ 'B::foo' : no accessible path to private member declared in virtual base 'D2'
return 0;
} |
Filed under: 之语言特性,边走编程 By
dutor @
July 6th, 2009,
20 views

你好!除了代码,此处没有多少原创之物,皆为本人搜集、整理、总结之记录与心得,欢迎转载分享!转载时请尽量注明出处,将不胜感激。祝你健康、快乐!
Be the first to comment on this entry.