public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Template base class: name lookup bug?
@ 2006-11-04  0:05 Kaz Kylheku
  2006-11-06 19:46 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Kaz Kylheku @ 2006-11-04  0:05 UTC (permalink / raw)
  To: gcc-help

 Kaz Kylheku wrote:
> #include <cstdio>
> 
> template <class T>
> class Base {
>     protected:
>         int numberBase;
> };
> 
> template <class T>
> class Derived : public Base<T> {
> public:
>     void print()
>     {
>         printf("bn = %d\n", numberBase);
>     }
> };
> 
> int main()
> {
>     Derived<int> d;
>     d.print();
>     return 0;
> }


New discovery: simply changing it to ``this->numberBase'' gets rid of
the error.

I forgot to mention that the latest version with which I reproduced this
is GCC 4.1.1.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Template base class: name lookup bug?
  2006-11-04  0:05 Template base class: name lookup bug? Kaz Kylheku
@ 2006-11-06 19:46 ` Ian Lance Taylor
  0 siblings, 0 replies; 3+ messages in thread
From: Ian Lance Taylor @ 2006-11-06 19:46 UTC (permalink / raw)
  To: Kaz Kylheku; +Cc: gcc-help

"Kaz Kylheku" <kaz@zeugmasystems.com> writes:

> New discovery: simply changing it to ``this->numberBase'' gets rid of
> the error.

Look for documentation on two-phase lookup.

Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Template base class: name lookup bug?
@ 2006-11-03 23:05 Kaz Kylheku
  0 siblings, 0 replies; 3+ messages in thread
From: Kaz Kylheku @ 2006-11-03 23:05 UTC (permalink / raw)
  To: gcc-help

In this example program class Derived<T> inherits from Base<T>. Yet an
unqualified name lookup of a base class member fails within
Derived<T>::print. If the identifier is qualified (Base<T>::numberBase)
then it works.

foo.cc: In member function `void Derived<T>::print()':
foo.cc:16: error: `numberBase' was not declared in this scope

#include <cstdio>

template <class T>
class Base {
    protected:
        int numberBase;
};

template <class T>
class Derived : public Base<T> {
public:
    void print()
    {
        printf("bn = %d\n", numberBase);
    }
};

int main()
{
    Derived<int> d;
    d.print();
    return 0;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-11-06 19:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-04  0:05 Template base class: name lookup bug? Kaz Kylheku
2006-11-06 19:46 ` Ian Lance Taylor
  -- strict thread matches above, loose matches on Subject: below --
2006-11-03 23:05 Kaz Kylheku

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).