[英]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.