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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:40:17+00:00 2026-05-27T21:40:17+00:00

There is a class definition and some bool functions which test some attributes class

  • 0

There is a class definition and some bool functions which test some attributes

  class MemCmd
  {
      friend class Packet;
      public:
        enum Command
        {
          InvalidCmd,
          ReadReq,
          ReadResp,
          NUM_MEM_CMDS
        };
      private:
        enum Attribute
        {
          IsRead,         
          IsWrite,             
          NeedsResponse,  
          NUM_COMMAND_ATTRIBUTES
        };

        struct CommandInfo
        {
          const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes;
          const Command response;
          const std::string str;
        };
        static const CommandInfo commandInfo[];
      private:
        bool
        testCmdAttrib(MemCmd::Attribute attrib) const
        {
          return commandInfo[cmd].attributes[attrib] != 0;
        }
      public:
        bool isRead() const         { return testCmdAttrib(IsRead); }
        bool isWrite() const        { return testCmdAttrib(IsWrite); }
        bool needsResponse() const  { return testCmdAttrib(NeedsResponse); }
  };

The question is how can I set NeedsResponse to true or false prior to calling needsResponse()

Please note that attributes is of type std::bitset

UPDATE:

I wrote this function:

void
setCmdAttrib(MemCmd::Attribute attrib, bool flag) 
{
    commandInfo[cmd].attributes[attrib] = flag;   // ERROR
}

void setNeedsResponse(bool flag)   { setCmdAttrib(NeedsResponse, flag); }

But I get this error:

error: lvalue required as left operand of assignment
  • 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-27T21:40:17+00:00Added an answer on May 27, 2026 at 9:40 pm

    From the comments:

    There are two problems here

    1. Data members that are const must be initialized in the class constructor.
    2. If the members are const there is no way to change them later.

    So, initialize (at least) the members that are supposed to have a constant value. Remove const from the members you intend to change later.

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

Sidebar

Related Questions

In short: is there some way I can modify a class definition such that
Is there a way to dynamically and conditionally create a class definition in PHP,
Is there a __CLASS__ macro in C++ which gives the class name similar to
Is there a class or set of functions built into the .NET Framework (3.5+)
Normally, I've seen prototype functions declared outside the class definition, like this: function Container(param)
I have this class/interface definitions in C# public class FooBase { ... protected bool
Is there a concept in C# of class definition and implementation similar to what
I have a class definition that looks like this: public class SolrObj { [SolrUniqueKey(id)]
In C#, given a class definition like this: public class SomeObject { public String
I have a code base, in which for Matrix class, these two definitions are

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.