Click here to Skip to main content
15,897,334 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Best alternative to GDI/GDI+ for simple 2D games Pin
Randor 24-Jul-09 9:27
professional Randor 24-Jul-09 9:27 
AnswerRe: Best alternative to GDI/GDI+ for simple 2D games Pin
Moak25-Jul-09 3:34
Moak25-Jul-09 3:34 
QuestionHow to calculate checksum Pin
resolvequestion24-Jul-09 9:05
resolvequestion24-Jul-09 9:05 
AnswerRe: How to calculate checksum Pin
Emilio Garavaglia24-Jul-09 9:27
Emilio Garavaglia24-Jul-09 9:27 
AnswerRe: How to calculate checksum Pin
«_Superman_»24-Jul-09 17:47
professional«_Superman_»24-Jul-09 17:47 
QuestionSupport asked for virtualising a program in Vista using TokenVirtualizationEnabled using SetTokenInformation Pin
Kees195824-Jul-09 8:57
Kees195824-Jul-09 8:57 
QuestionDSA algorithm Pin
sarroya24-Jul-09 7:38
sarroya24-Jul-09 7:38 
QuestionHow to store array in vector in C++ Pin
resolvequestion24-Jul-09 7:30
resolvequestion24-Jul-09 7:30 
AnswerRe: How to pass array inside Vector in C++ Pin
transoft24-Jul-09 7:57
transoft24-Jul-09 7:57 
AnswerRe: How to store array in vector in C++ Pin
«_Superman_»24-Jul-09 17:59
professional«_Superman_»24-Jul-09 17:59 
QuestionTab control implementation in MFC document / view application. [modified] Pin
Vaclav_24-Jul-09 5:55
Vaclav_24-Jul-09 5:55 
Questionsafely returning classes from functions... when and when not to construct ! Pin
paolosh24-Jul-09 5:04
paolosh24-Jul-09 5:04 
AnswerRe: safely returning classes from functions... when and when not to construct ! Pin
josda100024-Jul-09 8:21
josda100024-Jul-09 8:21 
GeneralRe: safely returning classes from functions... when and when not to construct ! Pin
paolosh24-Jul-09 23:48
paolosh24-Jul-09 23:48 
QuestionBeginner: How to access elements in a Variant array of Variants (8204) Pin
BeerFizz24-Jul-09 4:19
BeerFizz24-Jul-09 4:19 
QuestionReturning large objects from a function without unnecessarily invoking the constructor ! Pin
paolosh24-Jul-09 3:31
paolosh24-Jul-09 3:31 
AnswerRe: Returning large objects from a function without unnecessarily invoking the constructor ! Pin
transoft24-Jul-09 3:43
transoft24-Jul-09 3:43 
GeneralRe: Returning large objects from a function without unnecessarily invoking the constructor ! Pin
paolosh24-Jul-09 3:51
paolosh24-Jul-09 3:51 
GeneralRe: Returning large objects from a function without unnecessarily invoking the constructor ! Pin
peterchen24-Jul-09 3:58
peterchen24-Jul-09 3:58 
paolosh wrote:
I've debugged the presented code step by step and witnessed that the compiler deletes p itself on exit from test() !


It does not.
What happens is this:

new MyClass creates a new MyClass instance on the heap
return *p returns a COPY of that object

That copy is a temporary variable, and will be destroyed. However, the instance allocated on the heap will not be destroyed.

You may want to lear a bit more about C++ pointers, copy constructors and temporary values (it is not an easy topic).

When you understand these things, I would suggest my article about smart pointers[^] as an introduction to a common solution to your original question - "returning large objects from a function".

Don't attribute to stupidity what can be equally well explained by buerocracy.
My latest article | Linkify!| FoldWithUs! | sighist


GeneralRe: Returning large objects from a function without unnecessarily invoking the constructor ! Pin
paolosh24-Jul-09 4:09
paolosh24-Jul-09 4:09 
GeneralRe: Returning large objects from a function without unnecessarily invoking the constructor ! Pin
peterchen24-Jul-09 8:37
peterchen24-Jul-09 8:37 
GeneralRe: Returning large objects from a function without unnecessarily invoking the constructor ! Pin
transoft24-Jul-09 5:04
transoft24-Jul-09 5:04 
GeneralRe: Returning large objects from a function without unnecessarily invoking the constructor ! Pin
peterchen24-Jul-09 5:09
peterchen24-Jul-09 5:09 
GeneralRe: Returning large objects from a function without unnecessarily invoking the constructor ! Pin
transoft24-Jul-09 5:27
transoft24-Jul-09 5:27 
GeneralRe: Returning large objects from a function without unnecessarily invoking the constructor ! Pin
peterchen24-Jul-09 8:31
peterchen24-Jul-09 8:31 

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.