Click here to Skip to main content
15,918,109 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Common Controls Problem in XP but not in 2003 Pin
Mark Salsbery26-Jun-07 11:26
Mark Salsbery26-Jun-07 11:26 
QuestionTo set alignment of Text in static control Pin
Mushtaque Nizamani26-Jun-07 5:56
Mushtaque Nizamani26-Jun-07 5:56 
AnswerRe: To set alignment of Text in static control Pin
Mark Salsbery26-Jun-07 6:05
Mark Salsbery26-Jun-07 6:05 
GeneralRe: To set alignment of Text in static control Pin
Mushtaque Nizamani26-Jun-07 6:27
Mushtaque Nizamani26-Jun-07 6:27 
GeneralRe: To set alignment of Text in static control Pin
led mike26-Jun-07 7:00
led mike26-Jun-07 7:00 
GeneralRe: To set alignment of Text in static control Pin
Mark Salsbery26-Jun-07 7:03
Mark Salsbery26-Jun-07 7:03 
AnswerRe: Help to solve this memory leakage problem Pin
Iain Clarke, Warrior Programmer26-Jun-07 5:51
Iain Clarke, Warrior Programmer26-Jun-07 5:51 
QuestionSTL container Pin
tom groezer26-Jun-07 3:40
tom groezer26-Jun-07 3:40 
AnswerRe: STL container Pin
CPallini26-Jun-07 3:42
mveCPallini26-Jun-07 3:42 
AnswerRe: STL container Pin
Orhun Birsoy26-Jun-07 4:51
Orhun Birsoy26-Jun-07 4:51 
QuestionDelete operator Pin
tom groezer26-Jun-07 3:37
tom groezer26-Jun-07 3:37 
AnswerYou need a Garbage Collector! Pin
CPallini26-Jun-07 3:41
mveCPallini26-Jun-07 3:41 
Answer... or smart pointers Pin
Cedric Moonen26-Jun-07 3:47
Cedric Moonen26-Jun-07 3:47 
AnswerRe: Delete operator Pin
led mike26-Jun-07 5:23
led mike26-Jun-07 5:23 
GeneralRe: Delete operator Pin
tom groezer26-Jun-07 16:52
tom groezer26-Jun-07 16:52 
GeneralRe: Delete operator Pin
led mike27-Jun-07 4:45
led mike27-Jun-07 4:45 
QuestionPrivate functions Pin
tom groezer26-Jun-07 3:30
tom groezer26-Jun-07 3:30 
AnswerRe: Private functions Pin
Cedric Moonen26-Jun-07 3:38
Cedric Moonen26-Jun-07 3:38 
AnswerRe: Private functions Pin
Roger Stoltz26-Jun-07 3:57
Roger Stoltz26-Jun-07 3:57 
QuestionInline functions Pin
tom groezer26-Jun-07 3:18
tom groezer26-Jun-07 3:18 
AnswerRe: Inline functions Pin
Rajkumar R26-Jun-07 3:27
Rajkumar R26-Jun-07 3:27 
Questionhelp to solve this bug Pin
James_Programmer26-Jun-07 3:04
James_Programmer26-Jun-07 3:04 
AnswerRe: help to solve this bug Pin
Cedric Moonen26-Jun-07 3:15
Cedric Moonen26-Jun-07 3:15 
AnswerRe: help to solve this bug Pin
Iain Clarke, Warrior Programmer26-Jun-07 3:23
Iain Clarke, Warrior Programmer26-Jun-07 3:23 
/* line 1 */ char *m_tmpChar;
/* line 2 */ m_tmpChar=new char[100];
/* line 3 */ m_tmpChar="0";
/* line 4 */ delete [] m_tmpChar;


That's because you're making a fundamental mistake. m_tmpChar is not some magic string type - its a pointer to a character.


In line 2, you allocate a patch of memory big enough for 100 chars, and make m_tmpChar point there.
In line 3, you make that variable point to another patch of memory that holds the character '0' followed by a NULL. This might even be read only, depending on complier settings. In the process, you've forgotten where your recently allocated lump of 100 bytes was.
In line 4, you are asking delete to free the "0" patch of memory, which certainly wasn't created by new. As you are in debug mode, you are getting errors.

So you have 2 bugs - (a) deleting memory which wasn't created with new [giving you the fault], and (b) not deleting memory that *was* created by new [giving you the leak].

That was the long explanation. The short explanation:

Ask your teacher about strcpy, or read your lecture notes.

Pointers are one of those bits of learning that is really strange and bizarre, until it all clicks in your head. Then its just dangerous if you're not careful.

Iain.



GeneralRe: help to solve this bug Pin
James_Programmer26-Jun-07 3:48
James_Programmer26-Jun-07 3:48 

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.