版权声明:本文为博主原创文章,如有需要,可以转载,但请注明出处。 https://blog.csdn.net/xunye_dream/article/details/84500813
在学习DCI(一种面向对象软件架构模式)中,采用的一些宏,以表达Role的概念。现简单收录如下
#define ABSTRACT(...) virtual __VA_ARGS__ = 0
#define OVERRIDE(...) virtual __VA_ARGS__ override
#define EXTENDS(...), ##_VA_ARGS__
#define IMPLEMENTS(...) EXTENDS(__VA_ARGS__)
#define USE_ROLE(type) virtual type& get##type() const;
#define HAS_ROLE(type) USE_ROLE(type)
#define ROLE(type) get##type()
#define IMPL_ROLE(type) \
virtual type& get##type() const override\
{\
return const_cast<type&>(static_cast<const type&>(*this));\
}
=================================================
在继承体系中,添加虚析构函数。
namespace details
{
template<typename T>
struct Role
{
virtual ~Role() {}
};
}
#define DEFINE_ROLE(type) struct type : ::details::Role<type>