Casting vectors to void pointers

Hello ,

I want to cast STL vecyor to a void pointer....How do i go for it?

ex:

void *data;

vector<int>myvector;

Now i want data to hold all the values of vector....
Is it possible?If yes.....
Please help me....


Thanks in advance
Last edited on
As in vector the stored data is guaranteed to be in one continuous block of memory, you can do this :
data = static_cast<void*>(& myvector[0])
That works as long as sizeof( vector::value_type* ) == sizeof( void* ), which is not necessarily always the case
(though in most cases it is).

The real question is why do you want to do this in the first place?
Topic archived. No new replies allowed.