Dar*_*ioP 6 c++ constructor default c++11
我无法理解自动添加默认ctors背后的基本原理.特别是我觉得非常尴尬,每次我只需要添加一个空的虚拟析构函数,仅此而已,我放松了移动的东西,但添加它们我松散了副本和默认的东西,所以我最终添加所有这些代码:
virtual ~SomeClass(){} // you are the guilty!
//virtual ~SomeClass() = default // would be the same
SomeClass(SomeClass&&) = default; // no more auto-added
SomeClass& operator=(SomeClass&&) = default; // no more auto-added
SomeClass(const SomeClass&) = default; // but with the moves defined,
SomeClass& operator=(const SomeClass&) = default; // I'm now missing the copy
SomeClass(){} // and the default as well
Run Code Online (Sandbox Code Playgroud)
我确信有一个理由让我的课程变得丑陋,让我想要一个邪恶的宏观,我只是想知道它感觉更舒服.
| 归档时间: |
|
| 查看次数: |
163 次 |
| 最近记录: |