我有一個singlton的問題。單身的靜態可變位置
我應該在哪裏聲明單例類的靜態成員?
爲什麼不這樣工作
class singleton{
private:
static singleton & m_singleton;
public:
static singleton& get_instance{
return m_singleton;
}
}
,但我必須這樣
class singleton{
public:
static singleton& get_instance{
static singleton & m_singleton;
return m_singleton;
}
}
有什麼差異性?
我知道有另一種方法來使用指針,但現在我只是在談論使用一個對象的情況。
另外還有一個問題,單身人士使用指針和引用有什麼優點/缺點?
非常感謝!
更多的信息在這裏:http://stackoverflow.com/questions/1008019/c-singleton-design-pattern/1008289#1008289 – 2011-04-05 23:20:57