[英]Macro to make class noncopyable
跟随宏使类不可复制是否存在任何问题?
#define PREVENT_COPY(class_name) \
class_name(const class_name&) = delete;\
class_name& operator=(const class_name&) = delete;
class Foo
{
public:
PREVENT_COPY(Foo)
// .......
};
通常,通常构造宏,因此它们与常规语句一样在行尾需要分号。
因此,我建议:
#define PREVENT_COPY(class_name) class_name(const class_name&) = delete;\
class_name& operator=(const class_name&) = delete
用法:
class Foo
{
public:
PREVENT_COPY(Foo); // Semi-colon required.
// .......
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.