我有以下C ++ 14代码:
template<typename T>
struct Test{
static constexpr auto something{T::foo()};
};
这是完全正常的,只要T::foo()
是constexpr
为好。
现在我有something
是ODR使用,所以我需要提供一个命名空间声明。我应该使用什么语法?
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;