This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]