jmpopush
jmpopush

Reputation: 41

gcc template inherit problem

template<class T>
class TBase
{
public:
 typedef int Int;

 struct TItem
 {
  T Data;
 };

 int value;
};

template<class T>
class TClass:public TBase<T>
{
public:
 TBase<T>::TItem item; // error here. only when using type defined in base class.

 void func()
 {
  TBase<T>::value ++; // no error here!
 }
};

int main(int argc, char *argv[])
{
 TClass<int> obj;
 return 0;
}

In VC and Borland C++ compiler, they both can compile it. But gcc cannot compile it because it use two times to deal with template things. VC or BCB do not care unknown template name. Is there any way to suppress this function of gcc? Thank you!

Upvotes: 4

Views: 694

Answers (2)

Foo Bah
Foo Bah

Reputation: 26271

TItem is a type so you need the typename keyword. value is a field. The compiler correctly resolves value but needs to be told that TItem is actually a type.

Upvotes: 0

tauran
tauran

Reputation: 8036

Try it with:

typename TBase<T>::TItem item;

This link provides an explanation: http://pages.cs.wisc.edu/~driscoll/typename.html

Upvotes: 5

Related Questions