Error on GCC 3.4 release web page
Johan Bergman (KI/EAB)
johan.bergman@ericsson.com
Fri Sep 17 23:38:00 GMT 2004
Hi again,
Maybe you could also mention the following alternative corrected definition of C<T>::h.
It might save a lot of work for those struggling to make their code GCC 3.4 compliant.
template <typename T> struct C : B<T> {
using B<T>::m;
using B<T>::f;
using B<T>::n;
using B<T>::g;
void h ()
{
m = 0;
f ();
n = 0;
g ();
}
};
BR,
Johan
-----Original Message-----
From: Johan Bergman (KI/EAB)
Sent: den 18 september 2004 00:07
To: 'gcc@gnu.org'
Subject: Error on GCC 3.4 release web page
Hi,
There seems to be an error in the following example, found on http://gcc.gnu.org/gcc-3.4/changes.html.
In a template definition, unqualified names will no longer find members of a dependent base. For example,
template <typename T> struct B {
int m;
int n;
int f ();
int g ();
};
int n;
int g ();
template <typename T> struct C : B<T> {
void g ()
{
m = 0; // error
f (); // error
n = 0; // ::n is modified
g (); // ::g is called
}
};
You must make the names dependent by prefixing them with this->. Here is the corrected definition of C<T>::g,
template <typename T> void C<T>::g ()
{
this->m = 0;
this->f ();
this->n = 0
this->g ();
}
The problem with the example is that the member function g() in C<T> calls itself. The following should work better:
In a template definition, unqualified names will no longer find members of a dependent base. For example,
template <typename T> struct B {
int m;
int n;
int f ();
int g ();
};
int n;
int g ();
template <typename T> struct C : B<T> {
void h ()
{
m = 0; // error
f (); // error
n = 0; // ::n is modified
g (); // ::g is called
}
};
You must make the names dependent by prefixing them with this->. Here is the corrected definition of C<T>::h,
template <typename T> void C<T>::h ()
{
this->m = 0;
this->f ();
this->n = 0
this->g ();
}
My only change was that 'g' was replaced with 'h' in three places (two in the code and one in the text).
BR,
Johan
More information about the Gcc
mailing list