class Root
{
public:
virtual void FooRoot()
{
std::cout << __FUNCTION__ << std::endl;
}
virtual void BarRoot()
{
std::cout << __FUNCTION__ << std::endl;
}
};class Derived: virtual public Root
{
public:
virtual void Foo1()
{
std::cout << __FUNCTION__ << std::endl;
} virtual void Bar1()
{
std::cout << __FUNCTION__ << std::endl;
}
};sizeof(Derived) == 12, 其中经过调试,发现第一个4字节保存的是Derived的vptr,第三个4字节保存的是Root的vptr,第二个4个字节的内容是什么东西呢?我去访问它,结果violation access
解决方案 »
- 关于非模态对话框的问题
- Delphi 如何通过接口方法的DispID获取方法名称?
- 请问怎么样改变对话框背景颜色(所有对话框)
- 关于SetWindowsHookEx的小问题!请大家帮忙!
- 为什么最新版本的DSOFramer.ocx V1.2在Word文档打印预览后关闭总是出错?
- VISIO STUDIO INSTALLER 安装程序问题
- 如何实现所有控件的扁平效果???求教!!!!!
- 用CWnd::CreateControl创建的控件,如何得到它的接口
- 关于通讯速度和其它参数在串口通讯中如何变更的问题?
- 怎样在VC中调用Word进行传真文件转换
- 請問VC裡改變下拉菜單顯示的內容,用什麼函數?
- 另外的两百分(2)
我装了新的SDK.但也不应该啊.
与这句class Derived: virtual public Root中的virtual 关键字有关,即虚拟继承
补充信息:class Root
{
public:
virtual void FooRoot()
{
std::cout << __FUNCTION__ << std::endl;
}
virtual void BarRoot()
{
std::cout << __FUNCTION__ << std::endl;
}
};class Root2
{
public:
virtual void FooRoot2()
{
std::cout << __FUNCTION__ << std::endl;
}
virtual void BarRoot2()
{
std::cout << __FUNCTION__ << std::endl;
}
};class Derived: virtual public Root, virtual public Root2
{
public:
virtual void Foo1()
{
std::cout << __FUNCTION__ << std::endl;
} virtual void Bar1()
{
std::cout << __FUNCTION__ << std::endl;
}
};typedef void (*pFun)(void);
int main()
{
Derived d;
pFun fun = (pFun)*(int*)*(int*)&d;
fun(); fun = (pFun)*((int*)*(int*)&d+1);
fun(); fun = (pFun)*(int*)*((int*)&d+2);
fun(); fun = (pFun)*((int*)*((int*)&d+2)+1);
fun(); fun = (pFun)*(int*)*((int*)&d+3);
fun(); fun = (pFun)*((int*)*((int*)&d+3)+1);
fun(); getchar();
return 0;
}