error C2440: 'type cast' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'DWORD'

匿名 (未验证) 提交于 2019-12-03 02:34:02

问题:

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?

回答1:

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 LPCSTRin 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]); 


回答2:

My intention was to get rid of the error.

This worked perfectly: *(DWORD*)(offset+0x571) = (DWORD)factions.front();



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!