Re: Cannot find source of undefined identifier
From: Rob Williscroft (rtw_at_freenet.REMOVE.co.uk)
Date: 31 Mar 2004 04:18:39 GMT
Alf P. Steinbach wrote in news:email@example.com:
>> From the standard 14.6.2:
>> 3 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.
>> The relevent bit here is "... base class scope ... not examined ...
>> during an instantiation ..."
>> This is what requires use of this->base_member() or one of the
>> other forms of qualifying the name.
> Isn't it great with a language so complex that the practitioners
> such as you and me (and I prefer to believe most others ;-)) can't
> really predict what simple code will or will not do, or even why
> our compilers spit out error messages at us?
> I'm not sure how seriously I mean that.
Its a sentiment I've often shared, though oddly in this case (two-phase
lookup) although the standardese is complex, the intent isn't.
In (what I think off) the bad old days, templates were just fancy
macro's, there was *no* predicting when you wrote a template what
the code would actually do when it was instantiated.
All these lookup rules attempt to give us as much control as is
possible of which parts of a template are paramiterized and which
aren't. IMO a Good Thing(tm).
The real problem is that we have all learn't to write templates
with compilers that don't implement any or all of the rules.
We have learn't to exploit the macro-like capabilties of our
non-standard compilers, and some of us like it that way.
And nobody likes extra typing :).
> But I do think that that will be a main factor in the downfall
> of C++ and the ascendance of some replacement language, perhaps D,
> perhaps some other as-yet-not-thought-of language.
I think its way to early to tell, C++ has still plenty of legs in
A major problem the language has is that its a moving target. If
*all* compilers implemented the lookup rules (and did so by default)
then we would all learn these rules real' quick.
Having said that I'm sure an extra diagnostic, perhaps:
whatever.cpp:666: BTW did you mean to write:
Would help. Or if two-pahse lookup must be disabled, at least:
wathever.cpp:666: Warning: you should realy use this->is_goal to
access a member of a template-paramiter dependant base class.
It could get better. (*)
-- *) The value of this usenet posting may go down as well as up, consult you unsent advisor (**) **) The humor of this joke may vary from location to location, but it should work if you've met a dodgy pensions advisor :) http://www.victim-prime.dsl.pipex.com/