开发者

gcc template inherit problem

开发者 https://www.devze.com 2023-02-07 21:41 出处:网络
template<class T> class TBase { public: typedef int Int; struct TItem { T Data; }; int value; }; template<class T>
template<class T>
class TBase
{
public:
 typedef int Int;

 struct TItem
 {
  T Data;
 };

 int value;
};

template<class T>
class TClass:public T开发者_开发百科Base<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!


Try it with:

typename TBase<T>::TItem item;

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


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.

0

精彩评论

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

关注公众号