#include <iostream>
#define server() (Singleton::get_instance())
class Singleton
{
public:
static Singleton& get_instance()
{
static Singleton instance;
return instance;
}
void coutHello(){ std::cout << "hello\n";}
private:
Singleton()
{
std::cout<<"Singleton()"<<std::endl;
}
~Singleton()
{
std::cout<<"~Singleton()"<<std::endl;
}
};
int main(int argc, char *argv[])
{
server().coutHello();
server().coutHello();
return 0;
}
g++ test.cc -o main --std=c++11