错误C2440:'type cast':无法转换为'std :: _ Vector_iterator< _Ty,_Alloc>' 'DWORD'

时间:2010-08-24 16:17:50

标签: c++

我收到以下错误:

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 Studio 2005.这适用于较旧的Visual Studio,但不适用于此。下面是导致错误的代码:

std::vector<LPCSTR> factions;

...

*(DWORD*)(offset+0x571) = (DWORD)factions.begin(); <- error here

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

您的目标是摆脱错误或使程序正确吗?在后一种情况下,你必须告诉我们你实际上要做什么。

既然你没有我必须猜测。我猜您要将向量中第一个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]);

答案 1 :(得分:0)

我的意图是摆脱错误。

这非常有效:*(DWORD*)(offset+0x571) = (DWORD)factions.front();

相关问题