[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Stupid questions: part 234223/234228
From:       Kalle Dalheimer <kalle () dalheimer ! hh ! eunet ! de>
Date:       1998-08-14 19:51:50
[Download RAW message or body]

Sven Radej:
>Hi,
>
>look at this:
>
>complex operator+(complex a, complex x) 
>{
>complex c;
>
>c.re = a.re + x.re;
>c.im = a.im + x.im;
>return(c);
>}
>
>Isn't c deleted when this function exits? Or when does it get deleted? 
>Shouldn't  function  return by reference?

No, that would be dangerous because there would then be a reference to an
object that has already gotten out of scope.

The way you show it is correct, the object c itself is delete at the end of the
function, but a copy is made in the return statement.

Kalle

>
>Thanks.
> --
>Sven Radej
>
>KDE developer
>radej@kde.org
>Visit http://www.kde.org
--
Kalle Dalheimer              Contract programming for Unix
kalle@dalheimer.de           Technical writing
kalle@kde.org                Technical editing
kalle@oreilly.de             KDE Developer (MFCH)
mdalheimer@acm.org           It's open, it's source, it runs - must be KDE!
	

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic