If you try to access a member of a base template from a derived template (event if the member is public) you are getting a compilation error. This is a regression related to previous versions of the compiler (worked in 3.3.3) and I think its not ANSI C++ as well. For example, compiling the following code (in test.cpp) will issue these errors: $ g++ -c test.cpp test.cpp: In member function `virtual bool Derived<Concept>::test(Concept)': test.cpp:21: error: `xxx' undeclared (first use this function) test.cpp:21: error: (Each undeclared identifier is reported only once for each f unction it appears in.) ------------ test.cpp ------------ // The base template template <class Concept> class Base { public : int xxx; }; // The derived template template <class Concept> class Derived : public Base<Concept> { public : bool test(Concept p) { return (xxx > 10); // to fix this I need to modify it to: return (this->xxx > 10); } }; // usage bool call_test(Derived<int>& d) { return d.test(5); }
Does anyone read the release notes? Yes this is required by the C++ standard.
Subject: Re: A derived template cannot access base templat e members without using this On Dec 29, 2004, at 9:54 AM, Amos Ortal wrote: > Hi Andrew, > > Thank you for your fast reply, I saw the entry in the release notes > but it doesn't point to the standard and I could not find it. > > Can you please point me to the section in the standard that specify > this? 14.6, the whole section is about name resolution in templates. -- Pinski
Specifically, [temp.dep]/3. Besides, even if the release notes do not point you to a specific place in the standard, the fact that we even documented that it's a *wanted* change in behaviour, it means it has to be correct, don't you think?
BTW, I just added the standard reference to the release notes as well.
(In reply to comment #3): I agree that this is the expected behavior, although such a change, without any backward compatibility, makes it hard to upgrade to a new version of the compiler. In our specific case, we provide a generic library and a client that tried to upgrade found the error and didn't understand why (they didn't read the release notes as well). Also the error message doesn't help you to understand that this is a deliberate change.