Friend declaration and qualified-id

Hi there!

I have question about friend declaration.

1
2
3
4
5
6
7
class X;

class A
{
    friend class ::X;
    friend class X;
};


I don't know why, but if I remove the 1st line, g++'ll show the following errors in the 5th line:

error: expected type-name
error: friend declaration does not name a class or function


Why is that ? ::X has the same meaning as X here...
Last edited on
"if I remove the 1st line..."
Is "first line" line 1 or line 5 of your snippet?
It's line 1...
So... Does anyone know why is that ?
I've read how C++ behaves in this case, ::X and X are not exactly the same but there's nothing that should cause this behaviour.
It may be a small bug of the compiler
Well, I've used Comeau C++ Online in this case and it also showed an error (when I deleted the 1st line - the declaration).

error: the global scope has no tag named "X"


This compiler is compliant with the ISO standard ^.^

--------------------------

::X and X are not exactly the same


Yeah, I agree - but in this case they have the same meaning... (Class A is in global scope, so the name X isn't obscured by a local name X)...
So Comeau C++ Online has this bug too ?
It would be suspicious if GCC, Comeau and MSVC all had the same bug - it is not a bug.

It is the way that names are 'looked-up'
It is the way that names are 'looked-up'


Could you explain what 'look-up' is ?
Put in my own words :

Name-Look up is/are the procedure(s) used by the compiler to resolve identifier names (variable names, function names, class names etc).
A qualified name is some thing like namespace_name::class_name::member_name
- that is to say, a qulaified name specifies the scope.

An unqualified name is some like x - that is there is no mention of scope.

There is a large section on unqualifiedname-Lookup in the C++ standards document.
Last edited on
There is a large section on unqualifiedname-Lookup in the C++ standards document.


Well, I've read about qualified-names but I haven't found anything about this issue :/
Topic archived. No new replies allowed.