I have a class
class foo {
public:
foo();
foo( int );
private:
static const string s;
};
Where is the best place to initialize the string s in the source file?
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.
Anywhere in one compilation unit (usually a .cpp file) would do:
foo.h
foo.cpp
(*) According to the standards you must define
ioutside of the class definition (likejis) if it is used in code other than just integral constant expressions. See David’s comment below for details.