Aug 31, 2009 at 1:34pm
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 Aug 31, 2009 at 1:35pm
Aug 31, 2009 at 1:42pm
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])
Aug 31, 2009 at 1:58pm
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?