Click here to Skip to main content
15,915,513 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Mouse position Pin
Roger Allen4-Oct-02 7:05
Roger Allen4-Oct-02 7:05 
GeneralRe: Mouse position Pin
Anonymous4-Oct-02 7:54
Anonymous4-Oct-02 7:54 
GeneralCOleSafeArray::PutElement Pin
Kash4-Oct-02 5:58
Kash4-Oct-02 5:58 
GeneralRe: COleSafeArray::PutElement Pin
Ranjan Banerji4-Oct-02 8:50
Ranjan Banerji4-Oct-02 8:50 
QuestionHow to capture mouse movement with a derived base class Pin
work_to_live4-Oct-02 5:40
work_to_live4-Oct-02 5:40 
AnswerRe: How to capturing mouse movement with a derived base class Pin
Tomasz Sowinski4-Oct-02 5:51
Tomasz Sowinski4-Oct-02 5:51 
GeneralRe: How to capturing mouse movement with a derived base class Pin
work_to_live4-Oct-02 7:07
work_to_live4-Oct-02 7:07 
Generalproblem with CPtrArray Pin
Tom Putzeys4-Oct-02 5:29
sussTom Putzeys4-Oct-02 5:29 
Hi,

Can anyone explain the following problem, to do with CArray and CPtrArray?

My member variables are:

CArray<CMyClass,CMyClass> m_objects;
CPtrArray m_pointers;

I try to initialize them like this:

for(int i = 0; i < 5; i++){
   m_objects.Add(CMyClass());
   m_objects[i].m_nMember = i;
   m_pointers.Add((void*) &m_objects[i]);
}

In my paint function, I just loop through the pointers, cast them and output the value of m_nMember. Like this:

for(int i = 0; i < m_pointers.GetSize(); i++){
   int value = ((CMyClass*) m_pointers.GetAt(i))->m_nMember;
   //draw value to the screen
}


I'd expect the output to be: 0 1 2 3 4, but it's not; 1 to 4 are always correct, but the first value is always nonsensical.

I was able to solve the problem by using a different initialization:

for(int i = 0; i < 5; i++){
   m_objects.Add(CMyClass());
   m_objects[i].m_nMember = i;
}

m_pointers.SetSize(m_objects.GetSize());

for(i = 0; i < m_objects.GetSize(); i++){
   m_pointers.SetAt(i, (void*) &m_objects[i]);
}

But still I would like to understand why the first approach doesn't work. Anyone have a clue? Is it a bug or something?

Thanks,

Tom
GeneralRe: problem with CPtrArray Pin
Pavel Klocek4-Oct-02 6:34
Pavel Klocek4-Oct-02 6:34 
GeneralStored Procedures in DAO Pin
SamirSood4-Oct-02 5:22
SamirSood4-Oct-02 5:22 
Generalfind remote machine mac address Pin
Anonymous4-Oct-02 5:23
Anonymous4-Oct-02 5:23 
GeneralRe: find remote machine mac address Pin
Andreas Saurwein4-Oct-02 5:37
Andreas Saurwein4-Oct-02 5:37 
GeneralRe: find remote machine mac address Pin
Scott H. Settlemier4-Oct-02 5:51
Scott H. Settlemier4-Oct-02 5:51 
QuestionISO and UDF source? Pin
chen4-Oct-02 5:16
chen4-Oct-02 5:16 
AnswerRe: ISO and UDF source? Pin
Andreas Saurwein4-Oct-02 5:57
Andreas Saurwein4-Oct-02 5:57 
Questionhow to simulate an animal's random movement Pin
wangnanjing4-Oct-02 5:10
wangnanjing4-Oct-02 5:10 
AnswerRe: how to simulate an animal's random movement Pin
Scott H. Settlemier4-Oct-02 5:20
Scott H. Settlemier4-Oct-02 5:20 
GeneralRe: how to simulate an animal's random movement Pin
wangnanjing4-Oct-02 5:19
wangnanjing4-Oct-02 5:19 
GeneralRe: how to simulate an animal's random movement Pin
Scott H. Settlemier4-Oct-02 5:43
Scott H. Settlemier4-Oct-02 5:43 
AnswerRe: how to simulate an animal's random movement Pin
Andreas Saurwein4-Oct-02 5:30
Andreas Saurwein4-Oct-02 5:30 
GeneralCDialogBar Pin
lucy4-Oct-02 5:05
lucy4-Oct-02 5:05 
GeneralRe: CDialogBar Pin
Tomasz Sowinski4-Oct-02 5:16
Tomasz Sowinski4-Oct-02 5:16 
GeneralRe: CDialogBar Pin
lucy4-Oct-02 5:36
lucy4-Oct-02 5:36 
GeneralRe: CDialogBar Pin
Tomasz Sowinski4-Oct-02 5:48
Tomasz Sowinski4-Oct-02 5:48 
GeneralRe: CDialogBar Pin
lucy4-Oct-02 5:46
lucy4-Oct-02 5:46 

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.