P
Peter
Hi.
I remember a code snippet from "Thinking in C++" where "class" and
"struct" keywords were missing from a friend declaration. The example
was more or less like this (it came from a chapter about nested
classes and "friend" keyword):
struct Boo
{
struct Foo;
friend Foo; // neither "struct" nor "class" after "friend"
struct Foo{};
};
Tested with an older version of g++ it resulted in the following
errors:
"error: a class-key must be used when declaring a friend"
"error: friend declaration does not name a class or function"
However, Comeau handled the above fine. Which result is standard
compliant in this case? I think an elaborated specifier is usually
required in friend declarations, but I read somewhere there's an
exception in presence of forward declarations like in the code above.
What are the precise rules? When exactly can "struct/class" keywords
be omitted in friend declarations and how do the most recent versions
of g++ and MSVC handle this (do they obey the standard or not)?
I remember a code snippet from "Thinking in C++" where "class" and
"struct" keywords were missing from a friend declaration. The example
was more or less like this (it came from a chapter about nested
classes and "friend" keyword):
struct Boo
{
struct Foo;
friend Foo; // neither "struct" nor "class" after "friend"
struct Foo{};
};
Tested with an older version of g++ it resulted in the following
errors:
"error: a class-key must be used when declaring a friend"
"error: friend declaration does not name a class or function"
However, Comeau handled the above fine. Which result is standard
compliant in this case? I think an elaborated specifier is usually
required in friend declarations, but I read somewhere there's an
exception in presence of forward declarations like in the code above.
What are the precise rules? When exactly can "struct/class" keywords
be omitted in friend declarations and how do the most recent versions
of g++ and MSVC handle this (do they obey the standard or not)?