Game Development Community

Forward Declarations in GCC4

by Christopher Van Horn · in Torque Game Builder · 01/19/2006 (7:29 am) · 2 replies

I have discovered when using GCC4 "friend class xyz;" does not actually declare the class xyz.

Using "friend class xyz;" will give you the following error:
"ISO C++ forbids declaration of xyz with no type"

You have to change it to just "class xyz;" It is listed in gcc's bugzilla here.

About the author

Recent Threads


#1
01/19/2006 (8:23 am)
This isn't a bug as noted here.
Not a bug.  The clause you referred to:

  "A name nominated by a friend declaration shall be accessible in the scope of 
  the class containing the friend declaration."

actually means that the following code is not allowed:

  class A { class B {}; };
  class C {
    friend class A::B; // Error - A::B is not accessible inside C
  };

For your case, look at 11.4 paragraph 9:

  "For a friend class declaration, if there is no prior declaration, the class
that is specified
  belongs to the innermost enclosing non-class scope, but if it is subsequently
referenced,
  its name is not found by name lookup until a matching declaration is provided
in the innermost
  enclosing nonclass scope."
#2
01/19/2006 (9:53 am)
Thanks, for the correction.