#include <stdio.h>#include "Singleton.h"int printDemo(); //or put to a header file
int main(int argc, char *argv[]) {
Singleton *singletonObj = Singleton::GetInstance();
printDemo();
printf("(%s:%d)\n", __FUNCTION__, __LINE__);
singletonObj->SayHello();
return0;
}
运行结果
$ g++ Client.cpp Demo.cpp Singleton.cpp
$ ./a.out
GC construction
to get Singleton instance
Singleton construction
to get Singleton instance
(printDemo:8)singletonObj=0x190a010
###SayHello(10)###index=0
(main:9)
###SayHello(10)###index=1
GC destruction
Singleton destruction