【发布时间】:2017-04-09 13:49:21
【问题描述】:
template <typename T>
struct A {
void mem_func() {
// This works!!! Can access static_func<int>();
std::cout << T::template static_func<int>() << '\n';
}
template <typename K>
static constexpr bool static_func() { return true; }
template <typename T1>
typename std::enable_if<T::template static_func<T1>(), void> sfinae_func() {
// This breaks!!! T is an incomplete type??
std::cout << "This fails" <<'\n';
}
};
struct B : A<B> {
};
在这里,我不明白为什么 T::static_func 在成员函数 foo() 中工作,但是当我去实例化 sfinae_func 时,相同的 T::static_func 是不可访问的,因为 T 不完整!这怎么可能?
后续是这样的: 如果标准限制我在 enable_if 中访问 T::static_func,是否有解决方法在需要时用 T::static_func 隐藏 A::static_funct?
template <typename T1>
typename std::enable_if<T::template static_func<T1>(), void> sfinae_func()
如果调用 T 的 static_func 以使 T 的 static_func 隐藏 A 的 static_func 需要做什么来启用?
【问题讨论】:
标签: c++ c++11 templates sfinae crtp