Re: Templates question
Re: Templates question
- Subject: Re: Templates question
- From: David Fang <email@hidden>
- Date: Fri, 23 Feb 2007 19:27:20 -0500 (EST)
> > To fix it, you still need a prefix. You have to add "this->" in
> > front of the function call. Since "this" depends on a template
> > parameter, the compiler can figure things out and knows the code is
> > acceptable.
> >
>
> Another solution instead of this-> is to place the following
> declaration in class bar's definition:
> using foo<T>::SetUpRenderStates;
Hi,
(Yes, people on this list will do their best to answer pure C++
questions! Fire away.)
By qualifying the call to your_method(), (with "this->" or "base_class::"
you're telling the compiler to postpone the name lookup until template
*instantiation*. (Because a template-dependent base class can be
specialized with a completely different definition.) This is the idea
behind two-phase name lookup.
> > So, it isn't really an issue. Any modern C++ compiler should emit
> > this error. CodeWarrior is now defunct and doesn't qualify anymore.
> > I don't know about the latest MS compilers. The last time I
> > checked, VS.Net 2003 still had serious problems. I haven't checked
> > the 2005 editions. C++ really isn't their focus anymore.
>
> Visual C++ 2005 does not give an error for that code.
Not familiar with VC, but you might look for various options to enforce
standard conformance. For gcc, I recommend: -ansi -pedantic-errors.
Fact of life: C++ compilers are catching up in standard conformance.
*shrug*. A few big compiler vendors (including gcc) went through the
phase of trying to make use of templates more convenient, e.g. implicit
typename on template-dependent names. Unfortunately, convenience doesn't
equate to conformance, as seen by the frequent template questions.
template <const char* STR>
struct question {
question() { cout << STR << endl; }
~question() { cout << "I don\'t know." << endl; }
};
const char doh[] = "Why doesn't my old C++ code compile anymore?";
template class question<doh>;
Fang
_______________________________________________
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