單例類 靜態函式 2

2021-08-26 05:40:28 字數 618 閱讀 3702

// 說明:

// 1、為了不能被例項化,建構函式宣告為 protected 或者直接宣告為 private,如果使用new 則報錯

// 2、使用類變數,static singleton *instance; 問題來了,這傢伙必須被初始化才能用。(在29行)

#include

using

namespace

std;

class singleton ;

static singleton *instance;

public:

int test=0;

~singleton() {};

static singleton &get_instance()

};singleton *singleton::instance=nullptr;

int main(int argv, char **args)

編譯g++ singleton.cpp

結果

[lzc@localhost test]$ ./a.out 

1

時間類 靜態函式

corpyright c 2013,煙台大學計算機學院 all right reseved.完成日期 2014年4月1日 版本號 v1.0 輸入描述 問題描述 時間類!程式輸出 問題分析 演算法設計 include using namespace std class time void show t...

繼承 類函式 靜態函式

coding utf 8 類的繼承 1.子類繼承自父類,子類擁有父類的所有屬性和函式 2.子類繼承自父類,子類可以擁有自己獨有的屬性和函式,父類不可以使用子類獨有的屬性和函式 3.子類繼承自父類,子類可以重寫父類的函式 3.1 完全重寫,在子類中重新定義乙個和父類函式名稱一樣的函式,但是這個函式執行...

89 類的靜態函式

示例 1 include 2 include 3 include 4 using namespace std 56 類實現靜態函式管理靜態資料 7class myclass821 void go 2225 26void show 2730 31static void show2 int data 3...