![](/img/trans.png)
[英]error C2440: 'initializing' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'type *'
[英]error C2440: 'type cast' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'DWORD'
我收到以下错误:
error C2440: 'type cast' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'DWORD'
with
[
_Ty=LPCSTR ,
_Alloc=std::allocator<LPCSTR >
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
我使用的是Visual Studio2005。这适用于较旧的Visual Studio,但不适用于该版本。 继承人代码导致错误:
std::vector<LPCSTR> factions;
...
*(DWORD*)(offset+0x571) = (DWORD)factions.begin(); <- error here
我该如何解决?
您的目标是消除错误或使程序正确吗? 在后一种情况下,您必须告诉我们您实际上在尝试做什么。
既然你没有,我不得不猜测。 我的猜测是您要将向量中第一个LPCSTR
的地址转换为DWORD
。 如果您的代码在VS的早期版本中可用,则这是更可能的情况。 如果我是对的,请尝试以下操作:
*(DWORD*)(offset+0x571) = (DWORD)(&factions.front());
或这个:
*(DWORD*)(offset+0x571) = (DWORD)(&*factions.begin());
或这个:
*(DWORD*)(offset+0x571) = (DWORD)(&factions[0]);
如果要将存储在向量LPCSTR
转换为DWORD
请执行以下操作:
*(DWORD*)(offset+0x571) = (DWORD)factions.front();
或这个:
*(DWORD*)(offset+0x571) = (DWORD)(*factions.begin());
或这个:
*(DWORD*)(offset+0x571) = (DWORD)(factions[0]);
我的目的是摆脱错误。
这完美地工作了: *(DWORD*)(offset+0x571) = (DWORD)factions.front();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.