【发布时间】:2010-04-29 16:24:23
【问题描述】:
我正在尝试在派生类中使用模板化基类的成员变量,如下例所示:
template <class dtype>
struct A {
int x;
};
template <class dtype>
struct B : public A<dtype> {
void test() {
int id1 = this->x; // always works
int id2 = A<dtype>::x; // always works
int id3 = B::x; // always works
int id4 = x; // fails in gcc & clang, works in icc and xlc
}
};
gcc 和 clang 都对使用这个变量非常挑剔,并且需要显式范围或显式使用“this”。使用其他一些编译器(xlc 和 icc),事情就像我期望的那样工作。这是 xlc 和 icc 允许不标准代码的情况,还是 gcc 和 clang 中的错误?
【问题讨论】:
标签: c++ inheritance templates compiler-construction