我有一个关于选择哪个函数来初始化静态类成员的问题。哪个函数用于初始化静态类成员?
//Base.h
class Base
{
private:
static int count;
static int countInit()
{
return 10;
}
public:
Base()
{
}
};
//and Base.cpp
static int countInit()
{
return 0;
}
int Base::count=countInit();//member function is used.
static int local_count=countInit();//the local one in Base.cpp
可变Base::count
被初始化为Base::countInit()
而非Base.cpp定义的countInit()
。但local_count
由本地countInit
初始化。所以,我想知道,在这种情况下是否有像Koenig lookup的规则?
所以'INT基准::计数= countInit() ;'调用成员? –
@LuchianGrigore,是的,它的确如此。我不知道发生了什么事。 – chris
其中是“int Base :: count = countInit();”被调用?导致静态成员函数Base :: countInit()计数不会仅由countInit()超出Base类的作用域调用。 – lulyon