Re: C++ error in template of template class
Re: C++ error in template of template class
- Subject: Re: C++ error in template of template class
- From: Howard Hinnant <email@hidden>
- Date: Wed, 28 Dec 2005 11:08:50 -0500
On Dec 28, 2005, at 3:05 AM, Scott Fraser wrote:
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:
CodeWarrior will complain if you turn on "ISO C++ Template Parser" in
the language prefs.
On Dec 28, 2005, at 8:58 AM, Steve Checkoway wrote:
Section 14.6.2 "Dependent types" clause 3 says that this is
illegal. The simplest example of the code not working is:
template<typename T> struct bar { int j; };
template<typename T> struct baz : public bar<T>
{
baz() { j = 0; }
};
The above point reads:
In the definition of a class template or a member of a class
template, if a base class of the class template depends on a
template-parameter, the base class scope is not examined during
unqualified name lookup either at the point of definition of the
class template or member or during an instantiation of the class
template or member.
Right.
On Dec 28, 2005, at 8:58 AM, Steve Checkoway wrote:
The example given is a bit strange but basically, ...
You really have to wonder if the standard committee decides
arbitrarily what is valid and what is not.
<nod> At each meeting we have a contest to see who can come up with
the most outlandish rules. ;-) (Just kidding!)
I rewrote your minimum example with base/derived. My eyes were
beginning to cross with baz/bar. Here's a summary of what's legal
and what's not (the illegal parts being commented out):
template<typename T> struct base {int j; };
template<typename T> struct derived : public base<T>
{
derived()
{
// j = 0;
this->j = 0;
// derived<T>::base<T>::j = 0;
derived<T>::base::j = 0;
// derived::base<T>::j = 0;
derived::base::j = 0;
derived<T>::j = 0;
derived::j = 0;
base<T>::j = 0;
// base::j = 0;
}
};
These rules were generally designed to allow for "definition-time"
checking of templates, partial specializations of templates, and deal
with the ambiguities that can arise with the dual meaning of
'<' (less-than, start of template parameter list).
-Howard
_______________________________________________
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