6
我試圖使用模板化基類的成員變量在派生類,如在此示例中:使用成員變量
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和鐺都是對使用這個變量非常挑剔,並且需要明確的範圍或明確使用「this」。與其他一些編譯器(xlc和icc)一樣,事情按我的預期工作。這是xlc和icc的一種情況,它允許不符合標準的代碼或gcc和clang中的錯誤?
相似問題:http://stackoverflow.com/questions/11405/gcc-problem-using-a-member-of-a-base-class-that-depends-on-a-template-argument – 2010-04-29 16:29:25