幾個常用的c++設計巨集定義
阿新 • • 發佈:2019-02-14
//singleton模板實現
template <typename T>
struct Singleton{
static T& getInstance()
{
static T inst;
return inst;
}
protected:
Singleton() {}
private:
Singleton(const Singleton&);
Singleton& operator=(const Singleton&);
};
#define DEFINE_SINGLETON(type) struct type : Singleton<type>
//
#define ABSTRACT(...) virtual __VA_ARGS__ = 0
#define OVERRIDE(...) virtual __VA_ARGS__
#define EXTENDS(...) , ##__VA_ARGS__
#define IMPLEMENTS(...) EXTENDS(__VA_ARGS__)
namespace details
{
template <typename T>
struct Role
{
virtual ~Role() {}
};
}
#define DEFINE_ROLE(type) struct type : ::details::Role<type>