gcc template question

C

Chu Zhou

Hi, all here is my code:

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

struct TItem
{
T Data;
};

int value;
};

template<class T>
class TClass:public TBase<T>
{
public:
void func()
{
TBase<T>::value ++;
}
};

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!
 
I

Ian Collins

Hi, all here is my code:

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

struct TItem
{
T Data;
};

int value;
};

template<class T>
class TClass:public TBase<T>
{
public:
void func()
{
TBase<T>::value ++;
}
};

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!

Your problem description isn't very helpful! Which gcc version are you
using and what errors do you get?

The code looks OK and compiles with g++ 3.4.3 and 4.3.4.
 
C

Chu Zhou

Hi, all here is my code:
template<class T>
class TBase
{
public:
  typedef int Int;
  struct TItem
  {
   T Data;
  };
  int value;
};
template<class T>
class TClass:public TBase<T>
{
public:
  void func()
  {
   TBase<T>::value ++;
  }
};
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!

Your problem description isn't very helpful!  Which gcc version are you
using and what errors do you get?

The code looks OK and compiles with g++ 3.4.3 and 4.3.4.

Thanks a lot!

Sorry for the wrong code I post on. The real error one is here:

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 happened when using type defined in
base classes

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

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

red floyd

On 01/29/11 10:59 AM, Chu Zhou wrote:
Hi, all here is my code:
template<class T>
class TBase
{
public:
  typedef int Int;
  struct TItem
  {
   T Data;
  };
  int value;
};
template<class T>
class TClass:public TBase<T>
{
public:
  void func()
  {
   TBase<T>::value ++;
  }
};
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!
Your problem description isn't very helpful!  Which gcc version are you
using and what errors do you get?
The code looks OK and compiles with g++ 3.4.3 and 4.3.4.

Thanks a lot!

Sorry for the wrong code I post on. The real error one is here:

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 happened when using type defined in
base classes

This line should read

typename TBase<T>::TItem item;

gcc is correct here, VC and BCB are not.
 void func()
 {
  TBase<T>::value ++; // no error here
 }

};

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

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top