Does constant static member variables of a class or a struct in C++ need not be defined separately?
Is this correct?
struct test
{
const static int x;
};
int test::x;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
No that’s not correct. The definition must match the declaration and
xisconst int, notint. As aconstvariable of POD type it also needs to be initialized. E.g.As a
const staticmember of integral type, it is also allowed to supply the initializer in the definition of the class instead.