Is it possible to initialize a static const data member outside of the constructor? Can it be initialized at the same place where data member is declared?
class A {
private:
static const int a = 4;
/*...*/
};
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.
YES you can but only for int types.
If you want your static member to be any other type, you’ll have to define it somewhere in a cpp file.
Also, note that this rule have been removed in C++11, now (with a compiler providing the feature) you can initialize what you want directly in the class member declaration.