C++"View() = default"是什么?
What is "View() = default" in C++?
这是我在C++中从未见过的语法。
请参阅以下内容:
class View
{
private:
int screenSize;
int screenScale; //"the ZOOM"
Point origin;
public:
const int minScreenSize = 6;
const int maxScreenSize = 30;
View():screenSize(25),screenScale(2),origin(-10,-10){}
~View() = default;
View(const View&) = default;
View(View&&) = default;
View& operator=(const View&) = default;
View& operator=(View&&) = default;
View& myAdd() = delete;
}
是什么意思:
View() = default
和View() = delete
?
提前谢谢。
它告诉编译器为您的类生成默认的"默认构造函数"。
这是在 C++11 中引入的。
对应的是= delete;
,它将指示编译器不生成函数。
= default;
比空的用户定义的 consteuctor {}
更可取,因为根据定义,使用的已定义析构函数永远不会trivial
(即使它们是空的),但编译器生成的函数是。
更多细节在这里:
http://en.cppreference.com/w/cpp/language/member_functions#Special_member_functions
http://en.cppreference.com/w/cpp/language/default_constructor
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- C++避免重复声明的语法是什么
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- C++从另一个类访问公共静态向量的正确方法是什么
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- C++中名称篡改的目的是什么
- 在 c++ 中拥有一组结构的正确方法是什么?
- 这个指针和内存代码打印是什么?我不知道是打印垃圾还是如何打印我需要的值
- 是什么阻止DOMTimerCoordinator::NextID进入无休止的循环
- 派生类销毁的最佳实践是什么
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 'default-initialization in copy-initialization context'在C++中是什么意思?
- [class.union]/3 注释中"Absent default member initializers, ..."的句子的目的是什么?
- "default definition would be ill-formed"是什么意思?
- C++;编译过程中的警告"enabled by default"是什么意思?
- 在 Xcode 4.5 中,"C++ Standard Library"和"C++ Language Dialect"的"Compiler Default"是什么?
- "except that a default constructed array is not empty"是什么意思?
- 类的函数声明之后"default"是什么意思?
- C++"View() = default"是什么?