来自这里:
struct piecewise_construct_t {}; constexpr piecewise_construct_t piecewise_construct = {}; const int magic_number = 42; inline std::tuple<int> make_magic() { return std::tuple<int>( piecewise_construct, magic_number ); }
This function violates the ODR ([basic.def.odr] §3.2/6 ) twice because neither of the constructor 2 arguments receives an lvalue-to-rvalue conversion. They are therefore passed by address, but the address depends on the TU because const (and constexpr) implies internal linkage.
我最初认为它确实有作用,但问题在于magic_number
具有内部链接。由于它具有内部链接,它是否本质上将magic_number
视为不同翻译单元中的不同变量,因此不是相同变量的多个定义? 有人能引用C ++标准的最新工作草案来明确说明吗?
inline
所需的必要机制已经就位。 - Cheers and hth. - Alfinline
函数有不同的定义。这相当微妙。 - Cheers and hth. - Alf