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
From the comments:
There are two problems here
constmust be initialized in the class constructor.constthere is no way to change them later.So, initialize (at least) the members that are supposed to have a constant value. Remove
constfrom the members you intend to change later.