错误C2440:'type cast':无法从'std :: _ Vector_iterator转换'_Ty,_Alloc>'到'DWORD' [英] error C2440: 'type cast' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'DWORD'
问题描述
我得到以下错误:
错误C2440:'type cast':无法从'std :: _ Vector_iterator& _Ty,_Alloc>'to'DWORD'
with
[
_Ty = LPCSTR,
_Alloc = std :: allocator< LPCSTR&
]
没有可以执行此转换的用户定义转换运算符,或者不能调用运算符
Im使用Visual Studio 2005.这工作在较旧的Visual Studio,但不是在这一个。遇到导致错误的代码:
std :: vector< LPCSTR>派系;
...
*(DWORD *)(offset + 0x571)=(DWORD)factions.begin(); < - error here
如何解决这个问题?
因为你没有我必须猜测。我的猜测是你想将向量中第一个 LPCSTR
的地址转换为 DWORD
。如果你的代码在VS的以前版本中工作,这是更可能的情况。如果我是正确的请尝试这:
*(DWORD *)(offset + 0x571)=(DWORD)(& factions 。面前());
或:
*(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]);
I get the following error:
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
Im using Visual Studio 2005. This worked on older Visual Studio but not on this one. Heres the code causing errors:
std::vector<LPCSTR> factions;
...
*(DWORD*)(offset+0x571) = (DWORD)factions.begin(); <- error here
How can I solve this?
Is your goal to just get rid of the error or to make the program correct? In the latter case you would have to tell us what you are actually trying to do.
Since you didn't I have to guess. My guess is you want to convert an address of the first LPCSTR
in the vector to DWORD
. If your code worked in the previous version of VS, this is the more probable scenario. If I'm right try this:
*(DWORD*)(offset+0x571) = (DWORD)(&factions.front());
or this:
*(DWORD*)(offset+0x571) = (DWORD)(&*factions.begin());
or this:
*(DWORD*)(offset+0x571) = (DWORD)(&factions[0]);
If you want to convert the LPCSTR
stored at the front of your vector to DWORD
do this:
*(DWORD*)(offset+0x571) = (DWORD)factions.front();
or this:
*(DWORD*)(offset+0x571) = (DWORD)(*factions.begin());
or this:
*(DWORD*)(offset+0x571) = (DWORD)(factions[0]);
这篇关于错误C2440:'type cast':无法从'std :: _ Vector_iterator转换'_Ty,_Alloc>'到'DWORD'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!