static Member Function
// Test.h
class Test
{
private:
Test() ;
~Test() ;
public:
static Test &instance() ; // Maybe a singleton pattern
} ;
// Test.cpp
Test &Test::instance() // Don't respecify the static keyword!
{
static Test g_t ;
return g_t ;
}
当在类外定义一个静态成员是, 我们不能重复指定 static 关键字. 这个关键字只能出现在类中的声明中.
In C++ Primer:
When we define a static member outside the class, we do not respecify the static keyword. The keyword appears only with the declaration inside the class body.(p.469)