开发者

GCC template issues [duplicate]

This question already has an answer here: Closed 12 years ago.

Possible Duplicate:

problem with template inheritance

This code doesn't compile in GCC:

template <typename T>
struct Base
{
public:
 int x;
};

template <typename B>
struct Middle : public B
{
};

template 开发者_如何学编程<typename T>
struct Sub : public Middle<Base<T> >
{
public:
 void F()
 {
  x=1; // error: ‘x’ was not declared in this scope
 }
};

If either Base or Sub weren't template classes, it wouldn't complain. VC handles it.

Why?


Use this->x = 1; to tell the compiler that x is a (template-) dependent name. Note: What GCC does ot fine according to the standard, MSVC is just a bit more tolerant.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜