C++ error in template of template class
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