Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Continued confussion with C++
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
klopyrev




PostPosted: Wed Mar 07, 2007 1:51 am   Post subject: Continued confussion with C++

code:

// convert rectangular to polar coordinates
polar rect_to_polar(rect xypos)
{
     polar answer;
     
     answer.distance =
            sqrt( xypos.x * xypos.x + xypos.y * xypos. y);
     answer.angle = atan2(xypos.y, xypos.x);
     return answer;
}


Assuming the two structures used in that method are defined, wouldn't that method not work properly since the method returns a local variable that would cease to exist when the method returns?

KL
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Wed Mar 07, 2007 2:29 am   Post subject: RE:Continued confussion with C++

No.

The function works fine (assuming the struct types are properly defined). The struct is returned by value, rather than reference.
klopyrev




PostPosted: Wed Mar 07, 2007 2:35 am   Post subject: Re: Continued confussion with C++

Thanks for the response. I figured it out on my own after rereading the chapter about functions.

KL
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: