关闭

A* obj=new C(); obj->fun(); class C:public B { private: virtual fun()

587人阅读 评论(0) 收藏 举报
// tmpDerive.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
class A
{
public:
	virtual fun()
	{
		printf("A!\n");
	}
};
class B:public A
{
protected:
	virtual fun()
	{
		printf("B!\n");
	}
};

class C:public B
{
private:
	virtual fun()
	{
		printf("C!\n");
	}
};

class A1
{
private:
	virtual fun()
	{
		printf("A1!\n");
	}
};
class B1:public A1
{
protected:
	virtual fun()
	{
		printf("B1!\n");
	}
};

class C1:public B1
{
public:
	virtual fun()
	{
		printf("C1!\n");
	}
};
int main(int argc, char* argv[])
{
	A* obj=new C();
	obj->fun();
	C1* pobjC1=new C1();
	A1* obj1=pobjC1;
	printf("%p;%p\n",pobjC1,obj1);
	reinterpret_cast<C1*>(obj1)->fun();
	static_cast<C1*>(obj1)->fun();
	//obj1->fun();

	printf("Hello World!\n");
	return 0;
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2997753次
    • 积分:40325
    • 等级:
    • 排名:第93名
    • 原创:399篇
    • 转载:4555篇
    • 译文:5篇
    • 评论:610条
    文章分类
    最新评论