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
#include <iostream>
//~ #include <string>
 
using namespace std;
 
class Base
{
public:
	virtual void foo()
	{
		cout<<"Base::foo()"<<endl;
	}
};
 
class Derived: public Base
{
private:
	void foo()
	{
		cout<<"Derived::foo()"<<endl;
	}
};
 
int 
main()
{
	Derived  * pD = new Derived;
	Base * pB = pD;
	pB->foo();			//~ OK, call Derived::foo()
	//~ pD->foo();			//~ oops, Derived::foo() is private!
	return 0;
}

可见,权限检查发生在名字查找之时,而虚函数表的访问不带有权限检查。

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

Be the first to comment on this entry.

Name(required)
Mail (required),(will not be published)

RFC: Request For Comments. Orz..

Website(recommended)