• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
C++ error in template of template class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++ error in template of template class


  • Subject: C++ error in template of template class
  • From: Scott Fraser <email@hidden>
  • Date: Wed, 28 Dec 2005 00:05:27 -0800

I was writing a template class of a template class, and was getting some odd scoping errors, using Xcode 2.2 (gcc 4.??). CodeWarrior (9.x) does not complain about this:

class BaseClass {
public:
int BaseClassInt;


int Get0BaseInt() { return BaseClassInt; }
};

template <class T1> class FirstTemplateClass : public BaseClass {
public:
int FirstTemplateInt;

int Get1BaseInt() { return BaseClassInt; }
int Get1FirstInt() { return FirstTemplateInt; }
};

template <class T2> class SecondTemplateClass : public FirstTemplateClass<T2> {
public:
int SecondTemplateInt;


int Get2BaseInt() { return BaseClassInt; } // error: 'BaseClassInt' was not declared in this scope
int Get2FirstInt() { return FirstTemplateInt; } // error: 'FirstTemplateInt' was not declared in this scope
int Get2SecondInt() { return SecondTemplateInt; }
};

I can avoid the two reported errors by adding the scope modifier, "FirstTemplateClass<T2>::" in front of the two offending references. But the question is, why does the compiler complain in the first place??

My guess is that when one has a template of a template, an ambiguity has been introduced into the name resolution. I assume it is similar to inheriting from a common ancestor class through two different base classes. Was that the "BaseClassInt" of the "FirstTemplateClass <xxx>" class, or the "BaseClassInt" of the "FirstTemplateClass <yyy>" class? Both have a base class of "BaseClass", but each instantiation of "FirstTemplateClass" has a different "BaseClass", and the compiler can't tell which one without an explicit scope modifier.

Does that make sense?

Thanks.

Scott
-----
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: C++ error in template of template class
      • From: Howard Hinnant <email@hidden>
    • Re: C++ error in template of template class
      • From: Steve Checkoway <email@hidden>
  • Prev by Date: Re: OT: Virtual PC 7 / Visual Studio 2003
  • Next by Date: Re: OT: Virtual PC 7 / Visual Studio 2003
  • Previous by thread: Re: OT: Virtual PC 7 / Visual Studio 2003
  • Next by thread: Re: C++ error in template of template class
  • Index(es):
    • Date
    • Thread