c++14 static constexpr auto with odr usage
c++14 static constexpr auto with odr usage
我有以下 c++14 代码:
template<typename T>
struct Test{
static constexpr auto something{T::foo()};
};
这完全没问题,前提是T::foo()
也是一个constexpr
。
现在我有了使用 ODR something
,所以我需要提供一个命名空间声明。我应该使用什么语法?
template<typename T>
constexpr auto Test<T>::something;
不行。谢谢!
传递using
定义的类型名怎么样?
template <typename T>
struct Test
{
using someType = decltype(T::foo());
static constexpr someType something{T::foo()};
};
template<typename T>
constexpr typename Test<T>::someType Test<T>::something;
相关文章:
- C++ Usage of AsyncCallback
- 这是 basic.def.odr 部分的缺陷吗?
- 为什么显式模板实例化不会破坏 ODR?
- std::visit and std::variant usage
- (ODR 使用问题)在不同文件中priority_queue名称相同的结构
- 声明中不一致的no是否违反ODR?
- 是否使用静态 constexpr 变量 odr?
- 使用 -pthread 如何不违反 ODR 规则?
- QLoggingCategory::setFilterRules usage
- C++ std::initializer_list usage
- 为什么编译器不在同一翻译单元中警告 ODR 违规
- C++ standard: ODR and constexpr std::string_view
- ODR 使用的规则不适用于 Visual Studio
- ASAN 检测与动态加载库共享的类的 vtable 的 ODR 违规
- C++模板函数的默认参数的 ODR 规则
- 为什么调用成员函数不调用该对象的 ODR-USE?
- Direct3D typedef usage
- 功能过载和ODR如何共存?(C )
- 为什么结构声明在C++中违反了 ODR
- c++14 static constexpr auto with odr usage