Click here to Skip to main content
15,890,185 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder12-Jul-09 22:37
cofounderChris Maunder12-Jul-09 22:37 
PinnedHOW TO ASK A QUESTION PinPopular
Chris Maunder12-Feb-09 17:19
cofounderChris Maunder12-Feb-09 17:19 
Questionchange exe icon not work with multiple stage icon file. Pin
Le@rner1-May-24 2:26
Le@rner1-May-24 2:26 
AnswerRe: change exe icon not work with multiple stage icon file. Pin
Victor Nijegorodov1-May-24 4:21
Victor Nijegorodov1-May-24 4:21 
GeneralRe: change exe icon not work with multiple stage icon file. Pin
jschell15hrs 43mins ago
jschell15hrs 43mins ago 
AnswerRe: change exe icon not work with multiple stage icon file. Pin
CPallini45mins ago
mveCPallini45mins ago 
GeneralRe: change exe icon not work with multiple stage icon file. Pin
Dave Kreskowiak41mins ago
mveDave Kreskowiak41mins ago 
GeneralRe: change exe icon not work with multiple stage icon file. Pin
CPallini38mins ago
mveCPallini38mins ago 
QuestionSOLVED Posting "debug (window ) view ? Pin
Salvatore Terress30-Apr-24 2:51
Salvatore Terress30-Apr-24 2:51 
AnswerRe: Posting "debug (window ) view ? Pin
Maximilien30-Apr-24 2:56
Maximilien30-Apr-24 2:56 
AnswerRe: Posting "debug (window ) view ? Pin
Victor Nijegorodov30-Apr-24 3:40
Victor Nijegorodov30-Apr-24 3:40 
QuestionObjects hierarchy ? Pin
Salvatore Terress29-Apr-24 5:15
Salvatore Terress29-Apr-24 5:15 
AnswerRe: Objects hierarchy ? Pin
Richard MacCutchan29-Apr-24 6:29
mveRichard MacCutchan29-Apr-24 6:29 
QuestionHow to track "nested objects "? Pin
Salvatore Terress18-Apr-24 8:34
Salvatore Terress18-Apr-24 8:34 
AnswerRe: How to track "nested objects "? Pin
Mircea Neacsu18-Apr-24 9:13
Mircea Neacsu18-Apr-24 9:13 
GeneralRe: How to track "nested objects "? Pin
Salvatore Terress18-Apr-24 14:57
Salvatore Terress18-Apr-24 14:57 
GeneralRe: How to track "nested objects "? Pin
Salvatore Terress19-Apr-24 4:00
Salvatore Terress19-Apr-24 4:00 
GeneralRe: How to track "nested objects "? Pin
Mircea Neacsu19-Apr-24 4:31
Mircea Neacsu19-Apr-24 4:31 
GeneralRe: How to track "nested objects "? Pin
Salvatore Terress19-Apr-24 7:11
Salvatore Terress19-Apr-24 7:11 
GeneralRe: How to track "nested objects "? Pin
Mircea Neacsu19-Apr-24 7:43
Mircea Neacsu19-Apr-24 7:43 
GeneralRe: How to track "nested objects "? Pin
k505419-Apr-24 8:16
mvek505419-Apr-24 8:16 
Lets break this down:
1) The expression new Object creates a new instance of Object on the heap, and provides a pointer to the new object.
2) The expression foo( something ) makes a function call. We might be able to deduce that m_status() is a member function to some object, both from your descriptions elsewhere and the use of the m_ decoration, but that's not necessarily the case. It could be you are using m_ as a decoration for a menu object or a motorhome object or some other mystery object....

Together we have f(new Object) which (1) constructs a new Object on the heap, and then (2) calls a function f with a pointer to the newly constructed Object. What we don't know is if Object has a default constructor. It might not, in which case, as you observe over in the lounge, you must use f(new Object(param, ...). There may be multiple constructors, so you'll need to check the documentation for the Object to see which one is most appropriate.

If you create an object with new, at some point delete Object should to be used to recover the allocated memory1. It's seems unlikely the the called function would do that, as it cannot know whether the pointer to Object is a pointer to a stack or heap object. Trying to delete a stack object is almost certainly going to cause Bad Things™ to happen. Maybe an immediate abort, maybe an exception gets thrown or maybe just a silent mess up of your data, with no indication that bad things have happened until some time later in the program. So you're probably better off to not use new Object as a parameter to a function. In general you should prefer a smart pointer ( Dynamic memory management - cppreference.com ) to new/delete in new development. But maybe the function does expect its parameter to be newly constructed within the parameter list and will delete before it returns? We don't know.

Footnotes:
1 This isn't strictly true. If you only create one instance of an object, the memory will be recovered when the program exits. A number of GNU C stdlib routines do this, allocating a block of memory when first called and re-using it as needed. The allocated memory is only "lost" to the executing program - assuming virtual memory and one of the usual operating systems (e.g. window, linux, macos, etc). That might not be true for some specialized use operating systems or for "stand-alone" programming environments.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown

GeneralRe: How to track "nested objects "? Pin
Salvatore Terress19-Apr-24 9:48
Salvatore Terress19-Apr-24 9:48 
GeneralRe: How to track "nested objects "? Pin
k505419-Apr-24 10:58
mvek505419-Apr-24 10:58 
GeneralRe: How to track "nested objects "? Pin
Salvatore Terress20-Apr-24 15:38
Salvatore Terress20-Apr-24 15:38 
GeneralRe: How to track "nested objects "? Pin
Richard MacCutchan21-Apr-24 2:04
mveRichard MacCutchan21-Apr-24 2:04 

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.