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::v开发者_如何转开发ector<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]);
My intention was to get rid of the error.
This worked perfectly: *(DWORD*)(offset+0x571) = (DWORD)factions.front();
精彩评论