简体   繁体   English

在 header 文件中声明构造函数 '= default' 是否会破坏 ODR

[英]Does declaring a constructor '= default' in a header file break the ODR

If I define the destructor (or any autogenerated constructor) as default like this:如果我将析构函数(或任何自动生成的构造函数)定义为默认值,如下所示:

struct A { 
   ~A() = default;
};

And then include this in several translation units, does this break the ODR?然后将其包含在几个翻译单元中,这会破坏 ODR 吗? Can someone walk me through the steps at on the ODR page?有人可以引导我完成ODR页面上的步骤吗? Because i am struggling to understand if the compiler generated destructor will be inline or some other effect to prevent it from breaking the ODR.因为我很难理解编译器生成的析构函数是否会内联或其他一些效果以防止它破坏 ODR。

No ODR violation.没有违反 ODR。 Member functions are implicitly inline if they are defined inside the class body.如果成员函数在 class 主体内定义,则它们是隐式内联的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么显式模板实例化不会破坏 ODR? - Why does explicit template instantiation not break ODR? constexpr头文件中的全局常量和odr - constexpr global constants in a header file and odr C++ 构造函数默认值 header 文件 - C++ constructor default value header file 声明没有默认构造函数的字段 - Declaring a field without a default constructor 为什么在标题的结构中声明的模板不违反ODR和专业化呢? - Why templates declared in the struct on the header dont violate ODR and specialization does? 在C ++中声明静态/动态数组是否自动在每个元素上调用默认构造函数? - Does declaring a static/dynamic array in C++ call default constructor on each element automatically? 虚幻引擎 4.24.3:声明 TArray 时没有构造函数实例错误<fstring>在 header 文件中</fstring> - Unreal Engine 4.24.3: No instance of constructor Error when declaring TArray<FString> in a header file 有没有一种更优雅的方式在构造函数中声明默认变量? - is there a more elegant way of declaring default variables in a constructor? 在C ++的头文件中声明其构造函数后,如何使用全局对象? - how to use object global after declaring its constructor in header file in c++? 仅在C ++中声明默认构造函数 - Only declaring a default constructor in C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM