Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7620677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:59:39+00:00 2026-05-31T03:59:39+00:00

while googling for how to overload operator = I found that some examples return

  • 0

while googling for how to overload operator = I found that some examples
return value http://www.cprogramming.com/tutorial/operator_overloading.html
, while a friend of mine that is C++ guru long time ago told me to return reference. Also for example when I look at the STL source I saw stuff like:

  vector&
  operator=(const vector& __x);

so what is the correct way to do it ?

BTW if you are curious my friend told me that the reason why to return ref is beause built in types return l-value.

int x;
(x = 3) += 2;
// x is now 5.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:59:40+00:00Added an answer on May 31, 2026 at 3:59 am

    Other than special cases where you really, really know what you’re doing, it should return either class& or void. (And most of the time, returning void should just be a placeholder for “I’m being lazy and haven’t gotten around to making sure that returning class& makes sense”)

    Returning class is a bad idea because it wastes time and memory (it makes a copy!) in the normal case where the user doesn’t use the return value, and will thoroughly mislead a user who actually does use the return value (and still waste time making copies).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this in some code examples while googling : $sql = 'INSERT INTO
While googling I found two different sets of headers that need to be set
I've been googling for a while now, I found some not complete tutorials how
While googling, I see that using java.io.File#length() can be slow. FileChannel has a size()
Is this possible? I've spent quite a while googling and found plenty of people
While googling around for doing more css with less writing and I found this
How to configure the jsf mavenized project with hibernate. While googling i found many
I'm running this sample code I found while googling: SELECT MD5(RAND()) But, to my
After googling for a while, I'm aware that there quite a few ways to
While I'm googling/reading for this answer I thought I would also ask here. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.