未处理的异常:0x80000002:在Win CE上使用动态\u转换时数据类型未对齐 我有一个为Win 32平台编写的C++应用程序。我移植这段代码是为了支持WindowsCE平台ARMV4I
在下一行,它抛出异常“0x8000002:数据类型未对齐”:未处理的异常:0x80000002:在Win CE上使用动态\u转换时数据类型未对齐 我有一个为Win 32平台编写的C++应用程序。我移植这段代码是为了支持WindowsCE平台ARMV4I,c++,exception,visual-studio-2005,windows-ce,C++,Exception,Visual Studio 2005,Windows Ce,在下一行,它抛出异常“0x8000002:数据类型未对齐”: remoteplatformpl*platform=dynamic_cast(&handle); 这里的句柄类型是PlatformHandle,但实际上它指向RemotePlatformImpl对象。RemotePlatformImpl是PlatformHandle的子类 以下是VS2005调试器的汇编代码: RemotePlatformImpl* platform = dynamic_cast<RemotePlatformI
remoteplatformpl*platform=dynamic_cast(&handle);
这里的句柄类型是PlatformHandle,但实际上它指向RemotePlatformImpl对象。RemotePlatformImpl是PlatformHandle的子类
以下是VS2005调试器的汇编代码:
RemotePlatformImpl* platform = dynamic_cast<RemotePlatformImpl*>(&handle);
421C4F34 ldr r3, [pc, #0x464]
421C4F38 ldr r2, [pc, #0x45C]
421C4F3C mov lr, #1
421C4F40 mov rl, #0
421C4F44 mov r0, r8
421C4F48 str lr, [sp]
421C4F4C bl 421D9970
remoteplatformpl*platform=dynamic_cast(&handle);
421C4F34 ldr r3[pc,#0x464]
421C4F38 ldr r2[pc,#0x45C]
421C4F3C移动lr,#1
421C4F40移动rl,#0
421C4F44 mov r0,r8
421C4F48 str lr[sp]
421C4F4C bl 421D9970
如果需要其他信息,请告诉我
重复问题的最小代码:
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include <string>
using namespace std;
class PlatformHandle
{
public:
virtual ~PlatformHandle(){}
bool operator==(const PlatformHandle& that) const { return (this == &that); }
bool operator!=(const PlatformHandle& that) const { return !(this == &that); }
PlatformHandle(){}
};
class RemotePlatformImpl : public PlatformHandle
{
public:
virtual ~RemotePlatformImpl(){}
RemotePlatformImpl(string srvAddr, int ctrlPort, int dataPort): PlatformHandle(){}
};
void justTest( PlatformHandle& handle)
{
PlatformHandle& platform = dynamic_cast<RemotePlatformImpl&>(handle);
}
int _tmain(int argc, _TCHAR* argv[])
{
PlatformHandle* ph = new RemotePlatformImpl("",2020,2021);
justTest( *ph );
return 0;
}
#包括“stdafx.h”
#包括
#包括
#包括
使用名称空间std;
类平台句柄
{
公众:
虚拟~PlatformHandle(){}
bool操作符==(const PlatformHandle&that)const{return(this==&that);}
布尔运算符!=(const PlatformHandle&that)const{return!(this==&that);}
PlatformHandle(){}
};
类RemotePlatformImpl:公共平台句柄
{
公众:
虚拟~RemotePlatformImpl(){}
RemotePlatformImpl(字符串srvAddr,int-ctrlPort,int-dataPort):PlatformHandle(){}
};
无效测试(平台手柄和手柄)
{
平台手柄和平台=动态铸造(手柄);
}
int _tmain(int argc,_TCHAR*argv[]
{
PlatformHandle*ph=新的RemotePlatformImpl(“”,20202021);
justTest(*ph);
返回0;
}
我通过在VS2005项目设置中启用开关解决了这个问题:
Configuration Properties -> C/C++ -> Language -> Enable Run-Time Type Info
所需的额外信息是一个完整的、最少的复制行为的示例。它需要很多努力,因为它依赖于许多其他类。不过,让我看看我能不能做到。你确定你想投
&handle
而不是handle
?我试过了。在它成为RemotePlatformImpl&platform=dynamic_cast(句柄)之前;其中,句柄类型为PlatformHandle&.@Flexo:添加了最少的示例代码以进行复制
Configuration Properties -> C/C++ -> Language -> Enable Run-Time Type Info