关于ODR违规和模板变量 [英] About ODR-violations and template variables
问题描述
我知道链接时模板函数不会受到多个定义的影响,就像在类中定义的成员函数一样,默认情况下它们是内联的.此外,constexpr
对象具有内部链接,但是模板变量具有外部链接(我的意思是在命名空间范围和C ++ 14上都适用).
I know that template functions don't suffer of multiple definitions when linking, like member functions defined inside a class, which are inline by default. Also, constexpr
objects have internal linkage, but template variables have external linkage (I mean at namespace scope and for C++14 in both cases).
那怎么办?
template<class T>
constexpr T i_am_odr_safe{};
i_am_odr_safe
在C ++ 14中是否具有外部或内部链接?功能模板等多重定义是否安全?
Does i_am_odr_safe
have external or internal linkage in C++14? and is it safe regarding multiple-definitions like function templates?
换句话说,i_am_odr_safe
odr安全吗?
In other words, is i_am_odr_safe
odr-safe?
推荐答案
这是核心问题1713 ,其IIRC的方向是该变量模板将具有外部链接.
This is core issue 1713, the direction of which IIRC is that this variable template will have external linkage.
And no, this hasn't been resolved yet, which is why LWG decided to plaster inline
all over the variable templates in the standard library when it adopted A+B2 of P0604R0.
这篇关于关于ODR违规和模板变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!