c++多重继承+虚函数表
来源:互联网 发布:天天特价9.9淘宝网 编辑:程序博客网 时间:2024/06/05 10:00
class parent1
{
public:
virtual void print1() = 0;
virtual void print2() = 0;
};
class parent2
{
public:
virtual void print3() = 0;
virtual void print4() = 0;
};
class child1:public parent1,public parent2
{
public:
void print1()
{
cout << "print1" << endl;
}
void print2()
{
cout << "print2" << endl;
}
void print3()
{
cout << "print3" << endl;
}
void print4()
{
cout << "print4" << endl;
}
};
int main()
{
void* t = (void*)new child1();
parent2* p2 = (parent2*)t; //无类型信息,t不能直接转换为parent2,成员访问都会错位
cout << t << endl;
cout << p2 << endl; // t == p2
p2->print3(); //"print1"
/////////////////
child1* c = new child1();
p2 = c; //编译器根据类型做了地址偏移,赋值后p2 != c
cout << c << endl;
cout << p2 << endl; // t != p2
p2->print3(); //"print3"
getchar();
return 0;
}
- 多重继承与虚函数表
- 多重继承与虚函数表
- C++ 虚函数表 多重继承
- 多重继承下的虚函数表
- c++多重继承+虚函数表
- C++ 多重继承 虚继承 虚函数表 多态
- 多重继承与虚函数
- 多重继承和虚函数
- c++ 继承 多重继承 多态性 虚函数
- C++【多重继承和虚继承】
- 多重继承与虚函数表(虚函数二)
- C++对象模型 多重继承与虚函数表
- C++ 虚函数表研究 (二) 多重继承
- 多重继承的虚函数表与类型转换
- 多重继承与虚函数表的实现原理
- C++对象模型 多重继承与虚函数表
- [C++对象模型][8]多重继承与虚函数表
- C++多重继承,虚函数表的次序
- Fibonacci数列
- mybatis 懒加载
- C++字符数组的输入输出
- request.getContextPath()
- Java 调试
- c++多重继承+虚函数表
- 闭包与变量
- XML解析——DOM4J
- iOS待办事项APP界面分析
- 懵懂的值传递和应用传递
- CoordinatorLayout补齐资料篇
- android 事件处理机制之requestDisallowInterceptTouchEvent
- ros中yaml文件读写的一种实现
- MySQL中RBAC建表