1

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?

1

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.