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

C / C++ / MFC

 
AnswerRe: return value - destructor call? Pin
Iain Clarke, Warrior Programmer22-Jun-07 3:01
Iain Clarke, Warrior Programmer22-Jun-07 3:01 
GeneralRe: return value - destructor call? Pin
zqueezy22-Jun-07 3:12
zqueezy22-Jun-07 3:12 
GeneralRe: return value - destructor call? Pin
Iain Clarke, Warrior Programmer22-Jun-07 4:05
Iain Clarke, Warrior Programmer22-Jun-07 4:05 
AnswerRe: return value - destructor call? Pin
Nemanja Trifunovic22-Jun-07 3:03
Nemanja Trifunovic22-Jun-07 3:03 
GeneralRe: return value - destructor call? Pin
zqueezy22-Jun-07 3:24
zqueezy22-Jun-07 3:24 
GeneralRe: return value - destructor call? Pin
Nemanja Trifunovic22-Jun-07 3:28
Nemanja Trifunovic22-Jun-07 3:28 
AnswerRe: return value - destructor call? Pin
Iain Clarke, Warrior Programmer22-Jun-07 3:03
Iain Clarke, Warrior Programmer22-Jun-07 3:03 
AnswerRe: return value - destructor call? Pin
Taka Muraoka22-Jun-07 3:06
Taka Muraoka22-Jun-07 3:06 
zqueezy wrote:
The Destructor is somehow called for the return value and I don't know why...


The newClass object in your test function is created on the stack and so cannot be used by anyone once the function exits. So the compiler has to copy it into your B variable, then destroy the newClass object. I think you're getting two calls to the destructor because the compiler is copying the newClass object into a temporary "return value" object and then copying this one into the B variable. Google for something called "return value optimization" for info on how to get rid of this.

zqueezy wrote:
is there a way of not calling the destructor here?


Nope. The newClass object *must* be destroyed (since it's on the stack).

zqueezy wrote:
because I actually free some memory in my prog in the destructor


This is usually not the best way of designing things but if you absolutely have to do it like this, allocate the newClass object from the heap (using "new") and return a pointer to that.




I enjoy occasionally wandering around randomly, and often find that when I do so, I get to where I wanted to be [^].

Awasu 2.3 [^]: A free RSS/Atom feed reader with support for Code Project. 50% discount on the paid editions for CP members!

GeneralRe: return value - destructor call? Pin
zqueezy22-Jun-07 3:14
zqueezy22-Jun-07 3:14 
AnswerRe: return value - destructor call? Pin
zqueezy25-Jun-07 11:27
zqueezy25-Jun-07 11:27 
QuestionRotating Bitmaps !!!! Pin
Adno22-Jun-07 2:43
Adno22-Jun-07 2:43 
AnswerRe: Rotating Bitmaps !!!! Pin
rrrado22-Jun-07 3:05
rrrado22-Jun-07 3:05 
AnswerRe: Rotating Bitmaps !!!! Pin
Mark Salsbery22-Jun-07 5:55
Mark Salsbery22-Jun-07 5:55 
GeneralRe: Rotating Bitmaps !!!! Pin
Adno22-Jun-07 7:34
Adno22-Jun-07 7:34 
GeneralRe: Rotating Bitmaps !!!! Pin
Mark Salsbery22-Jun-07 7:58
Mark Salsbery22-Jun-07 7:58 
GeneralRe: Rotating Bitmaps !!!! Pin
Adno22-Jun-07 8:20
Adno22-Jun-07 8:20 
QuestionRemoving Redundant Functions Pin
[d3m0n]22-Jun-07 2:42
[d3m0n]22-Jun-07 2:42 
AnswerRe: Removing Redundant Functions Pin
zqueezy22-Jun-07 3:25
zqueezy22-Jun-07 3:25 
GeneralRe: Removing Redundant Functions Pin
[d3m0n]22-Jun-07 3:50
[d3m0n]22-Jun-07 3:50 
QuestionRe: Removing Redundant Functions Pin
David Crow22-Jun-07 4:45
David Crow22-Jun-07 4:45 
AnswerRe: Removing Redundant Functions Pin
[d3m0n]22-Jun-07 5:09
[d3m0n]22-Jun-07 5:09 
QuestionRe: Removing Redundant Functions Pin
David Crow22-Jun-07 5:52
David Crow22-Jun-07 5:52 
AnswerRe: Removing Redundant Functions Pin
Arris7422-Jun-07 7:47
Arris7422-Jun-07 7:47 
AnswerRe: Removing Redundant Functions Pin
[d3m0n]22-Jun-07 8:01
[d3m0n]22-Jun-07 8:01 
QuestionVideo Rendering using DirectShow Pin
Maynka22-Jun-07 2:25
Maynka22-Jun-07 2:25 

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.