【发布时间】:2017-04-11 09:41:41
【问题描述】:
具有静态成员 foo 的模板类。
template <typename... T>
struct A {
static constexpr bool foo = true;
};
A 的模板派生类试图访问 foo。
template <typename... T>
struct B : A<T...> {
void yo() {
std::cout << foo << '\n';
}
};
这失败了。谁能解释一下为什么??我可以通过直接访问它来解决它,比如A<T...>::foo,但是如果 B 有它自己的静态变量隐藏 foo 怎么办?
如果第三方/主要人员仅通过模板(例如TClass)知道 A 或 B,他们如何在不了解内部情况的情况下访问 TClass::foo?
【问题讨论】:
-
照原样,
foo是一个非依赖名称,您也可以使用this->foo使其依赖。
标签: c++ c++11 templates static