Home > Back-end >  A field how to set a default value?
A field how to set a default value?

Time:09-15

The union BYTE_CON_SN
{
BYTE m_bytSN [2].
Struct
{
BYTE m_Set0:1;
Unsigned int m_uiSN: 15;
} m_bitSN;
};
M_Set0 I want to set to 0.

Normal other structures, such as:
Struct stDemo
{
Int m_iSet=0;//in this syntax to set the default
}

This can be achieved? Or is a c + + on the failed to consider?
I don't want to every time a BYTE_CON_SN variables, the following sentence. M_bitSN. M_Set0=0;
With the deepening of the project because it is over, there may be other, even a few need to set,

CodePudding user response:

C + + does not in the class structure declaration/initialization bit-field members, I don't know why so design, but may be initialized in the constructor of the default list:
Struct BYTE_CON_SN
{
The union
{
BYTE m_bytSN [2].
Struct
{
BYTE m_Set0:1;
Unsigned int m_uiSN: 15;
};
};
BYTE_CON_SN () : m_uiSN (127) {};
};

CodePudding user response:

The upstairs is indeed a solution,
  • Related