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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:31:40+00:00 2026-05-18T08:31:40+00:00

Based on C++ Primer 4th edition (i.e. pp 105), bitset<32> bitvec; bitvec[0].flip(); // reverses

  • 0

Based on C++ Primer 4th edition (i.e. pp 105),

bitset<32> bitvec;

bitvec[0].flip(); // reverses the first bit.

My question is why the second line works? Based on

http://www.cplusplus.com/reference/stl/bitset/operator[]/

     bool operator[] ( size_t pos ) const;
reference operator[] ( size_t pos );

How can bitset::flit can be used on bool or reference?

Thank you

  • 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-18T08:31:41+00:00Added an answer on May 18, 2026 at 8:31 am

    “reference” returned by operator[] is not a C++ reference, it is a special proxy class that has flip() method.

    Pseudo code:

    class bitset
    {
       class reference
       {
       public:
          reference& flip()
          {
             bitset_.flip(pos_);
             return *this;
          }
    
          reference(bitset& obj)
          : bitset_(obj), pos_(pos)
          {
          }
    
       bitset& bitset_;
       size_t pos_;
       };
    
       reference operator[](size_t pos)
       {
          return reference(*this, pos);
       }
    }
    

    See source code of your STL implementation for details.

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

Sidebar

Related Questions

Based on the response to this question: Why does C++ have header files and
Based on this question it appears that the default template for CheckStyle will allow
Based on my previous question here my new concern is how do I unit
Based on this question I don't want to litter my ready stuff waiting for
Based on some other code I found from this site (This Question here -
Based on this question which was closed rather quickly: Trying to create a program
Based on info in the following question REST Content-Type: Should it be based on
Based on a simple test I ran, I don't think it's possible to put
Based on a few posts I've read concerning version control, it seems people think
Based on all my reading there should be one GC thread to invoke all

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.