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 3636722
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:04:09+00:00 2026-05-19T01:04:09+00:00

Consider the following code? I was wondering, if I change it from (Function body

  • 0

Consider the following code?

I was wondering, if I change it from (Function body still the same)

error_code& operator|=(const error_code &e)

to

error_code operator|=(const error_code &e)

Is there any potential bug that might possible occur? The only difference I see is, it will perform an extra copy operation, other than that, no big deal.

So, should I just stick to return by reference, or it doesn’t matter?


class error_code {
public:
 error_code() : hi(0), lo(0) {}
 error_code(__int64 lo) : hi(0), lo(lo) {}
 error_code(__int64 hi, __int64 lo) : hi(hi), lo(lo) {}

 // How about return by copy?
 error_code& operator|=(const error_code &e) {
  this->hi |= e.hi;
  this->lo |= e.lo;
  return *this;
 }

 __int64 hi;
 __int64 lo;
};

error_code operator|(const error_code& e0, const error_code& e1) {
 return error_code(e0.hi | e1.hi, e0.lo | e1.lo); 
}

int main() {
 error_code e0(1);
 error_code e1(2);
 e0 |= e1;
}
  • 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-19T01:04:09+00:00Added an answer on May 19, 2026 at 1:04 am

    Is there any potential bug that might possible occur?

    Yes. This won’t work as expected anymore:

    (ec |= x) = y;
    

    Now, this is a silly piece of code, no doubt about that, but

    1. it does work for other types and
    2. there might be other cases where this difference matters.

    For example, if your class error_code will have member functions modifying the object they are invoked for, then these will modify a temporary object if you return by copy instead of reference:

    (ec |= x).normalize();  // whatever "normalizing" error code means...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: class MyClass { template <typename Datatype> friend MyClass& operator<<(MyClass& MyClassReference,
Consider following code: typedef SomeType type_t[2]; SomeType * arr1 = new type_t; //new or
Consider the following code, public class StartUp { public StartUp(String[] test){} public static void
Consider the following code: struct Vec2 : IEquatable<Vec2> { double X,Y; public bool Equals(Vec2
Consider the following code which does not rollback the transaction if an exception is
Consider the following code snippet that takes user input (a date) and format it
Consider the following code: <!DOCTYPE html> <html lang=en> <head> <title>HTML</title> <meta charset=utf-8 /> <style
Consider the following code: respond_to do |format| format.js { render :layout => false }
I'm working on development of a social web application using Java. I need to
Using Glassfish 3.1 with Eclipselink as JPA provider on board. Got stateless bean with

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.