Click here to Skip to main content
15,879,326 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionTabbed control from Win 32 Pin
birajendu23-Jun-09 18:05
birajendu23-Jun-09 18:05 
QuestionC++ Compiler Warnings Pin
dipuks23-Jun-09 13:37
dipuks23-Jun-09 13:37 
AnswerRe: C++ Compiler Warnings Pin
Luc Pattyn23-Jun-09 14:09
sitebuilderLuc Pattyn23-Jun-09 14:09 
AnswerRe: C++ Compiler Warnings Pin
N a v a n e e t h23-Jun-09 15:56
N a v a n e e t h23-Jun-09 15:56 
GeneralRe: C++ Compiler Warnings Pin
David Crow24-Jun-09 3:11
David Crow24-Jun-09 3:11 
AnswerRe: C++ Compiler Warnings Pin
«_Superman_»23-Jun-09 16:26
professional«_Superman_»23-Jun-09 16:26 
AnswerRe: C++ Compiler Warnings Pin
KarstenK23-Jun-09 21:31
mveKarstenK23-Jun-09 21:31 
QuestionConsiderations and implementation of a method to copy the vector<t>::iterator</t> Pin
Cyrilix23-Jun-09 9:23
Cyrilix23-Jun-09 9:23 
My title is probably not very well phrased, but here is the problem. Let's say I've got functions a(), b(), where a() calls b(), and b() calls vector<T>::iterator iter = someVector.begin().

b() needs to pass this iterator down to a() via a void* mechanism, without returning it (essentially using reference passing), so more explicitly, the two functions are:

void a(void*& param);
void b(void*& param);

The problem is, we can't simply do something like this:

vector<T>::iterator iter = someVector.begin();
param = reinterpret_cast<void*>(iter)

This is because the compiler (MSVC9) will complain about trying to cast an iterator to a void*:

error C2440: 'reinterpret_cast' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'void *'

Likewise, I can't do something like...

vector&lt;T&gt;::iterator iter = someVector.begin();
param = reinterpret_cast<void*>(&iter)

...because even though this will compile, it will not work because begin() actually returns an iterator object and not a pointer to some memory location, so the memory address of that object will go out of scope (not sure when, but I'm guessing when you leave b()). So, because I can't do any of this, I thought that maybe I could do a memory copy of the iterator, pass it up as a void*, and then cast it back to an iterator, so something along these lines:

vector<T>::iterator iter = someVector.begin();
void* mem = malloc(sizeof(vector<T>::iterator));
//memcpy starting from &iter up to the size, into the malloc memory
param = mem;

And on the flip side, in order to decode my data, I'd do something like this:

vector<T>::iterator = reinterpret_cast<vector<T>::iterator>(param);

I'm wondering whether or not this idea of mine is feasible or will cause me many problems, or if there is a better way of doing what I'd like to do, given the limitations (can only pass by void* reference).

Thanks.
AnswerRe: Considerations and implementation of a method to copy the vector::iterator Pin
Stuart Dootson23-Jun-09 9:28
professionalStuart Dootson23-Jun-09 9:28 
GeneralRe: Considerations and implementation of a method to copy the vector::iterator Pin
Cyrilix23-Jun-09 10:25
Cyrilix23-Jun-09 10:25 
GeneralRe: Considerations and implementation of a method to copy the vector::iterator Pin
Stuart Dootson23-Jun-09 10:33
professionalStuart Dootson23-Jun-09 10:33 
GeneralRe: Considerations and implementation of a method to copy the vector::iterator [modified] Pin
Michael Dunn23-Jun-09 14:41
sitebuilderMichael Dunn23-Jun-09 14:41 
GeneralRe: Considerations and implementation of a method to copy the vector::iterator Pin
Cyrilix23-Jun-09 15:03
Cyrilix23-Jun-09 15:03 
Questiontransfer date time string to SYSTEMTIME Pin
includeh1023-Jun-09 6:44
includeh1023-Jun-09 6:44 
AnswerRe: transfer date time string to SYSTEMTIME Pin
Jijo.Raj23-Jun-09 7:02
Jijo.Raj23-Jun-09 7:02 
AnswerRe: transfer date time string to SYSTEMTIME Pin
Stuart Dootson23-Jun-09 7:12
professionalStuart Dootson23-Jun-09 7:12 
Question[SOLVED] Need help with WinAPI AlphaBlend() [modified] Pin
Rozis23-Jun-09 6:06
Rozis23-Jun-09 6:06 
Questionbase or super-like functionality in C++? Pin
Michael P. Scherer23-Jun-09 5:35
Michael P. Scherer23-Jun-09 5:35 
AnswerRe: base or super-like functionality in C++? Pin
Fernando A. Gomez F.23-Jun-09 6:04
Fernando A. Gomez F.23-Jun-09 6:04 
GeneralRe: base or super-like functionality in C++? Pin
Michael P. Scherer23-Jun-09 6:09
Michael P. Scherer23-Jun-09 6:09 
AnswerRe: base or super-like functionality in C++? Pin
Nemanja Trifunovic23-Jun-09 6:17
Nemanja Trifunovic23-Jun-09 6:17 
AnswerRe: base or super-like functionality in C++? Pin
Stuart Dootson23-Jun-09 6:54
professionalStuart Dootson23-Jun-09 6:54 
Questionhow to save image from webBrowser Control Pin
voo doo1223-Jun-09 5:32
voo doo1223-Jun-09 5:32 
QuestionSetFont at Runtime Pin
p_196023-Jun-09 5:15
p_196023-Jun-09 5:15 
Questionhow to replace " with \" Pin
Ash_VCPP23-Jun-09 4:31
Ash_VCPP23-Jun-09 4:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.