I worked on the class fractionas a CS assignment and wrote the following code:
fraction fraction::add(fraction other) {
fraction temp;
return temp;
}
This worked just fine by creating a new object fractionand then returning it to the calling code.
The question is, why did it work? My fraction tempmust go out of scope when the method addreturns and, therefore, is destroyed, but will be passed back to the calling code without any error.
Why does the return of something with a local area lead to the fact that it continues to exist after leaving the scope?
source
share