Click here to Skip to main content
15,795,402 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWhat MS SDK do you use and why? Pin
charlieg28-Mar-22 15:08
charlieg28-Mar-22 15:08 
AnswerRe: What MS SDK do you use and why? Pin
Richard MacCutchan29-Mar-22 2:26
mveRichard MacCutchan29-Mar-22 2:26 
GeneralRe: What MS SDK do you use and why? Pin
charlieg29-Mar-22 3:43
charlieg29-Mar-22 3:43 
QuestionLinked List Cleanup Pin
Calin Negru22-Mar-22 12:03
Calin Negru22-Mar-22 12:03 
AnswerRe: Linked List Cleanup Pin
Greg Utas22-Mar-22 12:26
mveGreg Utas22-Mar-22 12:26 
GeneralRe: Linked List Cleanup Pin
Calin Negru22-Mar-22 13:30
Calin Negru22-Mar-22 13:30 
GeneralRe: Linked List Cleanup Pin
Greg Utas24-Mar-22 8:19
mveGreg Utas24-Mar-22 8:19 
GeneralRe: Linked List Cleanup Pin
Calin Negru24-Mar-22 7:04
Calin Negru24-Mar-22 7:04 
Hey Greg, there`s more than one issue in the function I posted. Like how do you go about managing a pointer that has been passed to the function.

I`ve seen this code in a codeproject article:
void NukeA(A* p)
{
        p->DoThis();
        p->DoThat();
 
        delete p; // Kaboom! A dangling pointer is born

        p = nullptr;
}


My thought is that this is wrong because the original pointer (the pointer being passed) remains at the gates of the function unaffected by the changes inside NukeA();
void NukeSafelyA(A** p)
{
        (*p)->DoThis();
        (*p)->DoThat();
        delete *p; // Nice
        *p = nullptr;
}

My question is how do you go about assigning a pointer to the pointer being passed or assign the pointer being passed to a new pointer that is stated/declared in the body of the function;

void NukeSafelyA(A** p)
{
        (*p)->DoThis();
        (*p)->DoThat();
        A * Temp1;
        A * Temp2;
        (*p) = Temp1; //?
        Temp2 = (*p); //?

        delete *p; // Nice
        *p = nullptr;
}


modified 24-Mar-22 12:13pm.

GeneralRe: Linked List Cleanup Pin
Greg Utas24-Mar-22 7:13
mveGreg Utas24-Mar-22 7:13 
GeneralRe: Linked List Cleanup Pin
k505424-Mar-22 8:09
mvek505424-Mar-22 8:09 
GeneralRe: Linked List Cleanup Pin
Calin Negru24-Mar-22 22:12
Calin Negru24-Mar-22 22:12 
GeneralMFC MDI Change tab styles after Addview is completed via Property Sheet Pin
kittmaster21-Mar-22 11:55
kittmaster21-Mar-22 11:55 
QuestionMessage Closed Pin
21-Mar-22 11:28
Member 1496877121-Mar-22 11:28 
AnswerRe: how do I verify - "all the ducks in the row "? Pin
k505421-Mar-22 12:09
mvek505421-Mar-22 12:09 
GeneralMessage Closed Pin
21-Mar-22 16:28
Member 1496877121-Mar-22 16:28 
GeneralRe: how do I verify - "all the ducks in the row "? Pin
Richard MacCutchan21-Mar-22 23:38
mveRichard MacCutchan21-Mar-22 23:38 
GeneralMessage Closed Pin
24-Mar-22 11:36
Member 1496877124-Mar-22 11:36 
GeneralRe: how do I verify - "all the ducks in the row "? Pin
k505424-Mar-22 12:06
mvek505424-Mar-22 12:06 
GeneralMessage Closed Pin
24-Mar-22 14:25
Member 1496877124-Mar-22 14:25 
GeneralRe: how do I verify - "all the ducks in the row "? Pin
Richard MacCutchan24-Mar-22 22:49
mveRichard MacCutchan24-Mar-22 22:49 
GeneralMessage Closed Pin
25-Mar-22 11:17
Member 1496877125-Mar-22 11:17 
GeneralRe: how do I verify - "all the ducks in the row "? Pin
k505425-Mar-22 12:26
mvek505425-Mar-22 12:26 
GeneralMessage Closed Pin
25-Mar-22 15:25
Member 1496877125-Mar-22 15:25 
GeneralMessage Closed Pin
25-Mar-22 17:33
Member 1496877125-Mar-22 17:33 
GeneralRe: how do I verify - "all the ducks in the row "? Pin
k505428-Mar-22 6:26
mvek505428-Mar-22 6:26 

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.