Because there is no overload "="? But I instantiation assign a char types, sizeof return values assigned to char variable is a very common operation, define the template class when there are mistakes in grammar, to obtain huge guy see,
This is the error message:
Code:
enum class CMD { CMD_ERROR, CMD_NEWUSERJOIN }; Template The class Msg_Header { Public: Msg_Header () {} Type_MsgLength m_msglength=sizeof (Msg_Header & lt; Type_MsgLength & gt;); CMD m_cmd=CMD: : CMD_ERROR; int a; }; Template The class Msg_NewUserJoin: Msg_Header & lt; Type_MsgLength & gt; { Public: Msg_NewUserJoin () {} Msg_Header & lt; Type_MsgLength & gt; : : m_msglength=sizeof (Msg_NewUserJoin & lt; Type_MsgLength & gt;); Msg_Header & lt; Type_MsgLength & gt; : : m_cmd=CMD: : CMD_NEWUSERJOIN; }; Int main (void) { Msg_NewUserJoin & lt; Char> MSG. } CodePudding user response:
Type_MsgLength type is not variable, how can the assignment?
CodePudding user response:
template The class Msg_NewUserJoin: Msg_Header & lt; Type_MsgLength & gt; { Public: Msg_NewUserJoin () : Msg_Header & lt; Type_MsgLength & gt; () { M_msglength=sizeof (Msg_NewUserJoin & lt; Type_MsgLength & gt;); M_cmd=CMD: : CMD_NEWUSERJOIN; } }; CodePudding user response:
Line 22, 23, is to Msg_Header & lt;> The member is initialized? Initialize the constructor should be on the list, or where the statement direct assignment (c + + 11 and after support);
Look at no other problem, suggestion:
1, 22, 23 lines of behavior: what do you want to do
CodePudding user response:
refer to the second floor SleekStone response: template The class Msg_NewUserJoin: Msg_Header & lt; Type_MsgLength & gt; { Public: Msg_NewUserJoin () : Msg_Header & lt; Type_MsgLength & gt; () { M_msglength=sizeof (Msg_NewUserJoin & lt; Type_MsgLength & gt;); M_cmd=CMD: : CMD_NEWUSERJOIN; } }; Thank big hint, compiled by now, but also to add domain role character in front of the variable to compile, enum class CMD { CMD_ERROR, CMD_NEWUSERJOIN }; Template The class Msg_Header { Public: Msg_Header () {} Type_MsgLength m_msglength=sizeof (Msg_Header & lt; Type_MsgLength & gt;); CMD m_cmd=CMD: : CMD_ERROR; }; Template The class Msg_NewUserJoin: Msg_Header & lt; Type_MsgLength & gt; { Public: Msg_NewUserJoin () : Msg_Header & lt; Type_MsgLength & gt; () { Msg_Header & lt; Type_MsgLength & gt; : : m_msglength=sizeof (Msg_NewUserJoin & lt; Type_MsgLength & gt;); Msg_Header & lt; Type_MsgLength & gt; : : m_cmd=CMD: : CMD_NEWUSERJOIN; } }; Int main (void) { Msg_NewUserJoin & lt; Char> MSG. } CodePudding user response:
The reference 3 floor ztenv response: line 22, 23, is to Msg_Header & lt;> The member is initialized? Initialize the constructor should be on the list, or where the statement direct assignment (c + + 11 and after support); Look at no other problem, suggestion: 1, 22, 23 lines of behavior: what do you want to do 22, 23 the intent is to from Msg_Header & lt;> Inherited member variable assignment again, after I put line 22, 23 in the constructor body to compile, but why line 12, 13 on the outside of the constructor, there is no any error, and outside the constructor of the original line 22, 23, an error? Compile the code: enum class CMD { CMD_ERROR, CMD_NEWUSERJOIN }; Template The class Msg_Header { Public: Msg_Header () {} Type_MsgLength m_msglength=sizeof (Msg_Header & lt; Type_MsgLength & gt;); CMD m_cmd=CMD: : CMD_ERROR; }; Template The class Msg_NewUserJoin: Msg_Header & lt; Type_MsgLength & gt; { Public: Msg_NewUserJoin () : Msg_Header & lt; Type_MsgLength & gt; () { Msg_Header & lt; Type_MsgLength & gt; : : m_msglength=sizeof (Msg_NewUserJoin & lt; Type_MsgLength & gt;); Msg_Header & lt; Type_MsgLength & gt; : : m_cmd=CMD: : CMD_NEWUSERJOIN; } }; Int main (void) { Msg_NewUserJoin & lt; Char> MSG. } CodePudding user response:
reference 5 floor luvmdy reply: Quote: refer to the third floor ztenv response: line 22, 23, is to want to Msg_Header & lt;> The member is initialized? Initialize the constructor should be on the list, or where the statement direct assignment (c + + 11 and after support); Look at no other problem, suggestion: 1, 22, 23 lines of behavior: what do you want to do 22, 23 the intent is to from Msg_Header & lt;> Inherited member variable assignment again, after I put line 22, 23 in the constructor body to compile, but why line 12, 13 on the outside of the constructor, there is no any error, and outside the constructor of the original line 22, 23, an error? Compile the code: enum class CMD { CMD_ERROR, CMD_NEWUSERJOIN }; Template The class Msg_Header { Public: Msg_Header () {} Type_MsgLength m_msglength=sizeof (Msg_Header & lt; Type_MsgLength & gt;); CMD m_cmd=CMD: : CMD_ERROR; }; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull