Click here to Skip to main content
15,925,255 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerYes, it is possible Pin
Jake Palmer24-Jul-01 7:42
Jake Palmer24-Jul-01 7:42 
GeneralSTL list / iterator question Pin
24-Jul-01 6:57
suss24-Jul-01 6:57 
GeneralRe: STL list / iterator question Pin
Not Active24-Jul-01 7:19
mentorNot Active24-Jul-01 7:19 
GeneralRe: STL list / iterator question Pin
markkuk24-Jul-01 12:12
markkuk24-Jul-01 12:12 
GeneralRe: STL list / iterator question Pin
25-Jul-01 4:48
suss25-Jul-01 4:48 
GeneralRe: STL list / iterator question Pin
Joaquín M López Muñoz24-Jul-01 12:51
Joaquín M López Muñoz24-Jul-01 12:51 
GeneralRe: STL list / iterator question Pin
25-Jul-01 4:47
suss25-Jul-01 4:47 
GeneralRe: STL list / iterator question Pin
CodeGuy25-Jul-01 5:50
CodeGuy25-Jul-01 5:50 
If you have a vector<t>, then a derefenced vector<t>::iterator is T.

BUT ...
If you have a list<t>, then a dereferenced list<t>::iterator is not T, but rather an object that would look like the following:
class ListNode
{
T* pNextObj;
T data;
...
}

So this is a safety thing on the part of the list implementors to keep you straight -- if you casted to change type, you could not get back the original object again (because this is internal to each STL implementation).

However, given the following code, this would work:
list<int> l;
l.push_back(1);
DWORD dw = (DWORD)(&l.begin());

Then if I want to print the list entry,
typedef list<int>::iterator ListIntIter;
ListIntIter* pi = (ListIntIter*)dw;
cout << **pi << endl;

Alternatively, you can store the index of the iterator and then use STL's 'advance' algorithm.

One more note: I actually consider all of this slightly dangerous, because while you can hold an address to a list element, remember that the size and order of the list could change if you are performing other list operations in the meantime. If you are holding onto iterators because you always want to keep track of, say, the 3rd element, then remember that although the iterator itself will not change in a list, its overall position in the list may still shift. In this case, if you are always wanting the nth element, I would use 'advance' or switch back to a random access container like vector or deque.
GeneralOpening a window in a console application Pin
Adi Shavit24-Jul-01 6:54
Adi Shavit24-Jul-01 6:54 
QuestionHow do I add a custom mimize button? Pin
Tommy H D Svensson24-Jul-01 6:27
Tommy H D Svensson24-Jul-01 6:27 
AnswerRe: How do I add a custom mimize button? Pin
Tomasz Sowinski24-Jul-01 7:37
Tomasz Sowinski24-Jul-01 7:37 
GeneralTransparentBlt , Win95 ( not supported + problems ) Pin
Leon24-Jul-01 6:25
Leon24-Jul-01 6:25 
GeneralRe: TransparentBlt , Win95 ( not supported + problems ) Pin
24-Jul-01 10:32
suss24-Jul-01 10:32 
GeneralRe: TransparentBlt , Win95 ( not supported + problems ) Pin
Christian Graus24-Jul-01 13:04
protectorChristian Graus24-Jul-01 13:04 
QuestionWhat would be magical about the Control ID of a radio Button? Pin
tm24-Jul-01 6:09
tm24-Jul-01 6:09 
Generalconverting decimal to hexadecimal Pin
24-Jul-01 6:07
suss24-Jul-01 6:07 
GeneralRe: converting decimal to hexadecimal Pin
Not Active24-Jul-01 7:24
mentorNot Active24-Jul-01 7:24 
GeneralDialog problem Pin
24-Jul-01 5:56
suss24-Jul-01 5:56 
GeneralRe: Dialog problem Pin
24-Jul-01 7:27
suss24-Jul-01 7:27 
Generalthis sample doesnf help me! Pin
24-Jul-01 10:55
suss24-Jul-01 10:55 
GeneralRe: this sample doesnf help me! Pin
Carlos Antollini24-Jul-01 11:10
Carlos Antollini24-Jul-01 11:10 
QuestionID?? Pin
24-Jul-01 5:12
suss24-Jul-01 5:12 
AnswerRe: ID?? Pin
Christian Graus24-Jul-01 13:06
protectorChristian Graus24-Jul-01 13:06 
QuestionSerialize : How can I know if the loading from the file success ??? Pin
24-Jul-01 5:04
suss24-Jul-01 5:04 
AnswerRe: Serialize : How can I know if the loading from the file success ??? Pin
CMFC6.0VS.NETUser24-Jul-01 5:20
CMFC6.0VS.NETUser24-Jul-01 5:20 

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.