- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我刚读到 constexpr 和 inline 函数遵循一个定义规则,但它们的定义必须相同。所以我试了一下:
inline void foo() {
return;
}
inline void foo() {
return;
}
int main() {
foo();
};
错误:'void foo()' 的重新定义,
和
constexpr int foo() {
return 1;
}
constexpr int foo() {
return 1;
}
int main() {
constexpr x = foo();
};
错误:'constexpr int foo()' 的重新定义
那么究竟是什么意思,constexpr 和 inline 函数可以服从 ODR?
最佳答案
I just read that constexpr and inline functions obey one-definition rule, but they definition must be identical.
这是引用不同翻译单元中的内联函数。在您的示例中,它们都在同一个翻译单元中。
这包含在 draft C++ standard 中3.2
一个定义规则 [basic.def.odr] 说:
There can be more than one definition of a class type (Clause 9), enumeration type (7.2), inline function with external linkage (7.1.2), class template (Clause 14), non-static function template (14.5.6), static data member of a class template (14.5.1.3), member function of a class template (14.5.1.1), or template specialization for which some template parameters are not specified (14.7, 14.5.5) in a program provided that each definition appears in a different translation unit, and provided the definitions satisfy the following requirements. Given such an entity named D defined in more than one translation unit, then
并包括以下项目符号:
- each definition of D shall consist of the same sequence of tokens; and
关于c++ - 对于内联函数和 constexpr 函数, "obey ODR"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29287361/
我对多处理器编程很陌生。 在 article关于 x86 内存模型。 In a multiprocessor system, memory ordering obeys causality (memo
谁能给我解释一下为什么我的 position:absolute div 不服从我的 position:relative div? 我敢肯定它确实很简单,但我终究无法理解它是什么。 我希望看到 posi
我刚读到 constexpr 和 inline 函数遵循一个定义规则,但它们的定义必须相同。所以我试了一下: inline void foo() { return; } inline void
我正在VHDL中的一个项目上工作,我需要从开关中获取4位输入,并根据其他开关的值向右或向左移动一定数量的位,该按钮需要在向右/向左移位之间切换。但是,当我尝试在Xilinx ISE中实现代码时,出现以
看看这个CodePen明白我的意思: .perspective-container { margin: 50px 0; perspective: 1000px; perspective-o
我正在尝试使树数据结构遵守可编码协议(protocol)。树终止于遵守协议(protocol)“终端”的“某个对象”。终端扩展了 Codable。 树的每个节点都是一对。它有一个键和一个值。该值是一对
我是一名优秀的程序员,十分优秀!