几个常用的c++设计宏定义

来源:互联网 发布:网络监控机品牌 编辑:程序博客网 时间:2024/06/05 05: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>

0 0