下面的snipplet是否适用于为类定义所有其他方法生成的方法和构造函数?在类中正确使用`= delete`方法
struct Picture {
// 'explicit': no accidental cast from string to Picture
explicit Picture(const string &filename) { /* load image from file */ }
// no accidental construction, i.e. temporaries and the like
Picture() = delete;
// no copy
Picture(const Picture&) = delete;
// no assign
Picture& operator=(const Picture&) = delete;
// no move
Picture(Picture&&) = delete;
// no move-assign
Picture& operator=(Picture&&) = delete; // return type correct?
};
这将删除每个默认的编译器实现,只留下析构函数,对不对?如果没有它,我猜可能会(几乎)不可用,但我可以删除它,对吗?
返回类型Picture&
的移动分配operator=(Picture&&)
是否正确?如果我为返回类型写了Picture&&
,它会有所作为吗?
看起来好像C++在C++ 0x!中真的改变了很多,有趣的东西。 – briantyler 2011-04-16 14:19:55
这是一个更清晰的语法,然后将这些方法隐藏在“private”部分中,并且只声明*但不定义*它们。 – towi 2011-05-27 08:03:39