Click here to Skip to main content
16,006,442 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Something to understand to new and delete!? Pin
Zac Howland17-Nov-06 5:34
Zac Howland17-Nov-06 5:34 
GeneralRe: Something to understand to new and delete!? Pin
Roger Stoltz17-Nov-06 5:37
Roger Stoltz17-Nov-06 5:37 
GeneralRe: Something to understand to new and delete!? Pin
Zac Howland17-Nov-06 5:55
Zac Howland17-Nov-06 5:55 
GeneralRe: Something to understand to new and delete!? Pin
David Crow17-Nov-06 6:30
David Crow17-Nov-06 6:30 
AnswerRe: Something to understand to new and delete!? Pin
Viorel.17-Nov-06 2:35
Viorel.17-Nov-06 2:35 
GeneralRe: Something to understand to new and delete!? Pin
bosfan17-Nov-06 2:56
bosfan17-Nov-06 2:56 
GeneralRe: Something to understand to new and delete!? Pin
Zac Howland17-Nov-06 5:36
Zac Howland17-Nov-06 5:36 
AnswerRe: Something to understand to new and delete!? Pin
Zac Howland17-Nov-06 5:26
Zac Howland17-Nov-06 5:26 
break; wrote:
CMyClass* pMyClass = new CMyClass();
// and later
//
delete pMyClass;


As a general rule, only use the ()'s when you have an argument to pass the constructor. There are cases where using empty ()'s will actually call a function and you will get very different results from what you expect.

CMyClass* pMyClass = new CMyClass;
// later
delete pMyClass;
pMyClass = NULL;


or better yet:

</code>std::tr1::shared_ptr<CMyClass> pMyClass = std::tr1::shared_ptr<CMyClass>(new CMyClass);</code>


Calling delete on a NULL pointer will do nothing to it, but setting the pointer to NULL prior to deleting it will cause a memory leak (bad!).

If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac

QuestionOwn Messages Pin
baerten17-Nov-06 1:20
baerten17-Nov-06 1:20 
AnswerRe: Own Messages Pin
Roger Stoltz17-Nov-06 2:02
Roger Stoltz17-Nov-06 2:02 
GeneralRe: Own Messages Pin
baerten17-Nov-06 3:25
baerten17-Nov-06 3:25 
GeneralRe: Own Messages Pin
Roger Stoltz17-Nov-06 4:21
Roger Stoltz17-Nov-06 4:21 
AnswerRe: Own Messages [modified] Pin
Tony Hill17-Nov-06 2:03
professionalTony Hill17-Nov-06 2:03 
GeneralRe: Own Messages Pin
baerten17-Nov-06 3:19
baerten17-Nov-06 3:19 
AnswerRe: Own Messages Pin
Viorel.17-Nov-06 3:29
Viorel.17-Nov-06 3:29 
GeneralRe: Own Messages Pin
baerten17-Nov-06 4:03
baerten17-Nov-06 4:03 
AnswerRe: Own Messages Pin
S Douglas18-Nov-06 23:24
professionalS Douglas18-Nov-06 23:24 
QuestionShowing log messages from threads into a common ListBox Pin
Cyber Friend17-Nov-06 0:18
Cyber Friend17-Nov-06 0:18 
AnswerRe: Showing log messages from threads into a common ListBox Pin
Rage17-Nov-06 0:27
professionalRage17-Nov-06 0:27 
GeneralRe: Showing log messages from threads into a common ListBox Pin
Cedric Moonen17-Nov-06 1:32
Cedric Moonen17-Nov-06 1:32 
GeneralRe: Showing log messages from threads into a common ListBox Pin
Rage17-Nov-06 4:15
professionalRage17-Nov-06 4:15 
AnswerRe: Showing log messages from threads into a common ListBox Pin
Waldermort17-Nov-06 0:32
Waldermort17-Nov-06 0:32 
GeneralRe: Showing log messages from threads into a common ListBox Pin
Cyber Friend17-Nov-06 1:00
Cyber Friend17-Nov-06 1:00 
AnswerRe: Showing log messages from threads into a common ListBox Pin
David Crow17-Nov-06 3:15
David Crow17-Nov-06 3:15 
QuestionString Problem..... Pin
Programm3r17-Nov-06 0:12
Programm3r17-Nov-06 0:12 

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.