Click here to Skip to main content
15,910,787 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Application Hang Pin
cpp_prgmer24-Jun-07 19:00
cpp_prgmer24-Jun-07 19:00 
QuestionRe: Application Hang Pin
Hamid_RT22-Jun-07 4:34
Hamid_RT22-Jun-07 4:34 
AnswerRe: Application Hang Pin
Jonathan [Darka]22-Jun-07 4:54
professionalJonathan [Darka]22-Jun-07 4:54 
GeneralRe: Application Hang Pin
cpp_prgmer24-Jun-07 19:02
cpp_prgmer24-Jun-07 19:02 
GeneralRe: Application Hang Pin
cpp_prgmer25-Jun-07 0:45
cpp_prgmer25-Jun-07 0:45 
Questionphp.h header file missing Pin
Kiran Pinjala22-Jun-07 3:50
Kiran Pinjala22-Jun-07 3:50 
QuestionRe: php.h header file missing Pin
David Crow22-Jun-07 4:34
David Crow22-Jun-07 4:34 
Questionreturn value - destructor call? Pin
zqueezy22-Jun-07 2:45
zqueezy22-Jun-07 2:45 
hey folks,
I wrote a little wrapper for the gsl-library and had to face a problem I never had expected (and never noticed before).
It's a simple class-question... So first the code:
<br />
// Class Header<br />
class myClass<br />
{<br />
public:<br />
	myClass();<br />
	~myClass();<br />
	myClass Testfunction();<br />
	int val;<br />
};<br />
<br />
// Class Implementation<br />
myClass::myClass()<br />
{<br />
	val=0;<br />
}<br />
<br />
myClass::~myClass()<br />
{<br />
	int t = 0;<br />
	int h = t;<br />
	this->val = val;<br />
	cout << "Destructor called\n";<br />
}<br />
<br />
myClass myClass::Testfunction()<br />
{<br />
	myClass newClass;<br />
	newClass.val = 7;<br />
	return newClass;<br />
}<br />
<br />
// Main<br />
int main()<br />
{<br />
	myClass A;<br />
	myClass B;<br />
	cout << "Calling test function\n";<br />
	B = A.Testfunction();<br />
<br />
	cout << "Print out value:\n";<br />
	cout << B.val << "\n";<br />
<br />
<br />
	cout << "Waiting for user...\n";<br />
	cin.get();<br />
}<br />


Allright... actually there shouldn't be any destructor called BEFORE the cin.get().
The output is:
<br />
Calling test function<br />
Destructor called                  // WHY???<br />
Destructor called                  // WHY???<br />
Print out value:<br />
7<br />
Waiting for user...<br />

The Destructor is somehow called for the return value and I don't know why...
And even if I get an explanation... is there a way of not calling the destructor here? (Compiler setting???)
because I actually free some memory in my prog in the destructor and when the memory is freed I never get it back... Frown | :(
any idea??

thx in advance
zqueezy
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 
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 

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.