Click here to Skip to main content
15,919,500 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: STL - compile warning Pin
Mike Burston15-Oct-01 12:38
Mike Burston15-Oct-01 12:38 
GeneralRe: STL - compile warning Pin
User 988515-Oct-01 12:45
User 988515-Oct-01 12:45 
GeneralCStatic problem Pin
15-Oct-01 10:28
suss15-Oct-01 10:28 
GeneralRe: CStatic problem Pin
Christian Graus15-Oct-01 10:30
protectorChristian Graus15-Oct-01 10:30 
GeneralRe: CStatic problem Pin
15-Oct-01 10:40
suss15-Oct-01 10:40 
GeneralRe: CStatic problem Pin
J Patel15-Oct-01 11:06
J Patel15-Oct-01 11:06 
GeneralRe: CStatic problem Pin
Michael Dunn15-Oct-01 12:34
sitebuilderMichael Dunn15-Oct-01 12:34 
Questionnew and delete, why does this work? Pin
Sam C15-Oct-01 10:22
Sam C15-Oct-01 10:22 
Hi,

Going over some code in a multithreaded library I came across a snippet that bewilers me, and I was hoping one of you can make sense of it for me. It is part of a multi-threaded application. First there a global structure declared.

struct CustomStruct
{
  CWnd* pCwnd;
  int* pInt;
  long* plong;
}


These are the same declarations but I can't recall them. But they are all pointers to some value. Then in one member function part of a class there is this call.

...
CustomStruct* pCS=new CustomStruct;

pCS->pCwnd=AfxGetMainWnd();
pCS->Int=&IntVariable;
pCS->plong=&LongVariable;

CreateThread(...(Pass the above struct address as LPVOID)


And in the static function for the thread we have

CustomStruct* pCS=(CustomStruct*)wParam;
CWnd* pCwnd=pCS->pCwnd;
int* pInt=pCS->pInt;
long* plong=pCS->plong;

delete pCS;


How does the delete portion of the code work? I don't understand how we can delete the structure here and still have access to the new pointers we declared in the function? How can we delete the structure and still have the data stored in the pointer still be valid? Did we not get rid of that data with delete? I'm confused please explain.

Thanks in Advance.


Sam C
----
Systems Manager
Hospitality Marketing Associates
AnswerRe: new and delete, why does this work? Pin
Tim Smith15-Oct-01 10:27
Tim Smith15-Oct-01 10:27 
GeneralRe: new and delete, why does this work? Pin
Sam C15-Oct-01 11:54
Sam C15-Oct-01 11:54 
AnswerRe: new and delete, why does this work? Pin
Tomasz Sowinski15-Oct-01 10:28
Tomasz Sowinski15-Oct-01 10:28 
GeneralRe: new and delete, why does this work? Pin
Sam C15-Oct-01 11:52
Sam C15-Oct-01 11:52 
GeneralRe: new and delete, why does this work? Pin
Mike Burston15-Oct-01 12:29
Mike Burston15-Oct-01 12:29 
GeneralRe: new and delete, why does this work? Pin
PJ Arends15-Oct-01 13:07
professionalPJ Arends15-Oct-01 13:07 
GeneralRe: new and delete, why does this work? Pin
Sam C15-Oct-01 13:46
Sam C15-Oct-01 13:46 
AnswerRe: new and delete, why does this work? Pin
Sam C15-Oct-01 13:48
Sam C15-Oct-01 13:48 
GeneralATL Pin
mimi15-Oct-01 9:13
mimi15-Oct-01 9:13 
GeneralCArray "How to" Pin
RobJones15-Oct-01 7:23
RobJones15-Oct-01 7:23 
GeneralRe: CArray "How to" Pin
Carlos Antollini15-Oct-01 7:38
Carlos Antollini15-Oct-01 7:38 
GeneralRe: CArray "How to" Pin
RobJones15-Oct-01 7:55
RobJones15-Oct-01 7:55 
GeneralRe: CArray "How to" Pin
Carlos Antollini15-Oct-01 8:22
Carlos Antollini15-Oct-01 8:22 
GeneralRe: CArray "How to" Pin
Carlos Antollini15-Oct-01 8:40
Carlos Antollini15-Oct-01 8:40 
GeneralRe: CArray "How to" Pin
RobJones15-Oct-01 9:20
RobJones15-Oct-01 9:20 
GeneralRe: CArray "How to" Pin
Christian Graus15-Oct-01 10:29
protectorChristian Graus15-Oct-01 10:29 
GeneralRe: CArray "How to" Pin
RobJones15-Oct-01 11:15
RobJones15-Oct-01 11:15 

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.