c++ - C++ - 初始化静态成员自己的方法
问题描述
是否可以使用自己的方法初始化静态成员,例如。初始化()?
例子:
class Foo
{
//some private variables
public:
static Bar example;
//some methods
}
然后在 main.cpp 中调用它,如:
Foo::example.initialize(argument);
当然,它不起作用。它也缺乏封装,因为变量是公共的。我希望它是私有的并且只初始化一次。除了用方法初始化它之外,我没有任何其他选择。