Tuesday, 17 September 2013

Way to initialize static members in the header

Way to initialize static members in the header

Given is a class with a static member.
class BaseClass {
static std::string bstring;
}
String has obviously to be default-initialized outside of the class.
std::string BaseClass::bstring {"."};
If I include the above line in the header along with the class, I get a
symbol multiply defined error. It has to be defined in a separate cpp
file, even with include guards or pragma once.
Isn't there a way to define it in the header?

No comments:

Post a Comment