Click here to Skip to main content
15,896,557 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralRe: help to solve this bug Pin
James_Programmer26-Jun-07 3:56
James_Programmer26-Jun-07 3:56 
GeneralRe: help to solve this bug Pin
Iain Clarke, Warrior Programmer26-Jun-07 4:33
Iain Clarke, Warrior Programmer26-Jun-07 4:33 
GeneralRe: help to solve this bug Pin
James_Programmer26-Jun-07 5:00
James_Programmer26-Jun-07 5:00 
GeneralRe: help to solve this bug Pin
James_Programmer26-Jun-07 5:14
James_Programmer26-Jun-07 5:14 
GeneralRe: help to solve this bug Pin
Iain Clarke, Warrior Programmer26-Jun-07 5:47
Iain Clarke, Warrior Programmer26-Jun-07 5:47 
GeneralRe: help to solve this bug Pin
James_Programmer26-Jun-07 6:01
James_Programmer26-Jun-07 6:01 
GeneralRe: help to solve this bug Pin
Mark Salsbery26-Jun-07 7:47
Mark Salsbery26-Jun-07 7:47 
Questionbrowse ... Pin
tasumisra26-Jun-07 2:33
tasumisra26-Jun-07 2:33 
AnswerRe: browse ... Pin
ahmad_ali26-Jun-07 6:45
ahmad_ali26-Jun-07 6:45 
GeneralRe: browse ... Pin
tasumisra26-Jun-07 20:52
tasumisra26-Jun-07 20:52 
GeneralRe: browse ... Pin
ahmad_ali26-Jun-07 22:55
ahmad_ali26-Jun-07 22:55 
QuestionData Types Pin
tasumisra26-Jun-07 1:34
tasumisra26-Jun-07 1:34 
AnswerRe: Data Types Pin
aatul26-Jun-07 1:41
aatul26-Jun-07 1:41 
AnswerRe: Data Types Pin
KarstenK26-Jun-07 3:27
mveKarstenK26-Jun-07 3:27 
QuestionEncode using DirectShow Pin
Maynka26-Jun-07 0:58
Maynka26-Jun-07 0:58 
AnswerRe: Encode using DirectShow Pin
Mark Salsbery26-Jun-07 6:22
Mark Salsbery26-Jun-07 6:22 

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.