Issue with pointer redirection in inherited clauses
John Fine
johnsfine@verizon.net
Wed May 6 01:19:00 GMT 2009
Tyler Earman wrote:
> "I have noticed that when (this is C++) inheriting a templatized derived
> class from a templatized base that in g++, references to elements of the
> base class have to be qualified with this-> or with the name of the base
> class put in front. But this is NOT needed in the Windows C++ compilers
> so far as I can see.
>
GCC is doing the correct thing according to the C++ standard. I
personally think the C++ standard is bad and this feature makes C++ a
worse language than it was before compilers enforced this language behavior.
When coding to work around this problem, I find both this->name and
base_class::name are ugly constructs. I don't use either to work around
this problem. Instead I use using directives, such as:
template <class X>
class my_container : public std::vector<X>
{
typedef std::vector<X> super;
using super::size;
using super::empty;
typedef typename super::iterator iterator;
At the start of most classes, I typedef the major base class as "super"
(not directly relevant to the current issue, but it helps).
Then I have the appropriate using super:: declarations to identify all
the function and variable names from that super class which will be used
bare in the current class. You can't use using declarations for types
from the base class, so those are best done with the typedef typename
construct.
More information about the Gcc-help
mailing list