tags:

views:

30

answers:

2

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  A: 

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]);
Maciej Hehl
A: 

My intention was to get rid of the error.

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

Seth
Maciej Hehl
If your intention is to get rid of the compilation error then you can just delete the line. If your intention is for your code to work correctly, then you need to understand what it's supposed to do first.
interjay
@seth: "My intention was to get rid of the error" And here we have exhibit A demonstrating why software sucks.
John Dibling
Welcome to Stack Overflow, Seth. The section at the bottom of the page is reserved for *answers* to the question. What you've posted here isn't an answer; it's a response to Maciej's answer, so it should go in the *comment* section. But you weren't allowed to post to the comment section because you didn't log in using the same credentials you used to post the question. If you had, then you would have been exempted from the usual restriction that comments aren't allowed from people with less than 50 reputation points. Use the "contact us" link below to request an admin to merge your accounts.
Rob Kennedy