• Advertisement

Archived

This topic is now archived and is closed to further replies.

This topic is 5718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, What is the differences between CMyObject & myfunction(); and CMyObject * myfunction(); Which is the fastest ? What are the advantages and disavantages of each declaration ? Thanks

Share this post


Link to post
Share on other sites
Advertisement
I suggest you take a really good look at http://www.parashift.com/c++-faq-lite/references.html

If you already are familiar with references as parameters, but are just wondering about them in regards to return values, scroll down to 8.3 and read that.

Share this post


Link to post
Share on other sites
quote:
Original post by elis-cool
Well... I have never even seen that!
If you overload += for a class, you normally return a reference to *this.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
another thing..

passing classes as parameters can also invoke that particular classes constuctor..this can be very bad if you want your routines to be as fast as possible. say youve got a vector class and youve overloaded all the math operators (+,-,+=,-=,etc.etc.)..if you didnt do it correctly you may be calling your vector classes constructor or copy constuctor hundreds possibly thousands of unneeded times per frame. we try to only pass classes as pointers, references and constants..unless you absolutely need to do otherwise..

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
passing classes as parameters can also invoke that particular classes constuctor..

No it doesn''t. That''s the whole point of passing things by reference: their constructors are NOT called.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:

passing classes as parameters can also invoke that particular classes constuctor



quote:

No it doesn''t. That''s the whole point of passing things by reference: their constructors are NOT called.



Ehm, yes it does call a constructor, particularly the copy constructor. When it comes to classes pass-by-value means call-copy-constructor. The author of the first quote never said anything about reference parameters.

Share this post


Link to post
Share on other sites

  • Advertisement