The code: has made calls to private member via object pointer
#include <iostream>
using std::cout;
using std::endl;
class A
{
public:
virtual void foo1(){cout<<"A::foo1()"<<endl;}
private:
virtual void foo(){cout<<"A::foo()"<<endl;}
};
class B:private A
{
private:
virtual void foo1(){cout<<"B::foo1()"<<endl;}
public:
virtual void foo(){cout<<"B::foo()"<<endl;}
};
int main()
{
B b;
A *a=(A *)&b;
a->foo1();
A a1;
B *b1=(B *)&a1;
b1->foo();
return 0;
}
/*
The code above makes calls to private member via object pointer, pls explain why.
This question is mentioned first in the following link, thank the original initiator.
http://expert.csdn.net/Expert/topic/1307/1307940.xml?temp=.5337946
*/
using std::cout;
using std::endl;
class A
{
public:
virtual void foo1(){cout<<"A::foo1()"<<endl;}
private:
virtual void foo(){cout<<"A::foo()"<<endl;}
};
class B:private A
{
private:
virtual void foo1(){cout<<"B::foo1()"<<endl;}
public:
virtual void foo(){cout<<"B::foo()"<<endl;}
};
int main()
{
B b;
A *a=(A *)&b;
a->foo1();
A a1;
B *b1=(B *)&a1;
b1->foo();
return 0;
}
/*
The code above makes calls to private member via object pointer, pls explain why.
This question is mentioned first in the following link, thank the original initiator.
http://expert.csdn.net/Expert/topic/1307/1307940.xml?temp=.5337946
*/
...全文
相关推荐
AI智能+智慧小区安防管理平台建设方案 智慧小区AI安防平台建设方案.ppt
AI智能+智慧小区安防管理平台建设方案 智慧小区AI安防平台建设方案
AI智能+智慧小区安防管理平台建设方案.ppt
智慧方案
GitLens 深度指南:从代码溯源到工程上下文治理
代码变更溯源是软件工程的基础能力,其本质是理解‘为什么改’而非仅知‘谁改的’。它依托 Git 历史、PR 元数据与 CI/CD 上下文,构建可交互的变更语义图谱,支撑跨团队协作、遗留系统维护与技术债治理。在 DevOps 与规模化协同场景下,高效追溯能力直接决定故障定位速度、Code Review 质量和知识传承效率。GitLens 通过行级上下文聚合、Timeline 因果链视图与远程平台深度集成,将分散在 GitHub/GitLab、Jira、CI 系统中的碎片信息实时映射至编辑器内,成为工程师理解代码
AI智能+智慧工厂安防管理平台建设方案.ppt
智慧方案
智慧园区综合安防管理平台建设方案.ppt
智慧方案


