Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I read in the 3.4.1.9 clause of the C++11 standard:

Name lookup for a name used in the definition of a friend function (11.3) defined inline in the class granting friendship shall proceed as described for lookup in member function definitions. If the friend function is not defined in the class granting friendship, name lookup in the friend function definition shall proceed as
described for lookup in namespace member function definitions.

Later, in the 11.3.6 clause I found:


A function can be defined in a friend declaration of a class if and only if the class is a non-local class (9.8), the function name is unqualified, and the function has namespace scope. [ Example:
class M {
friend void f() { }
// definition of global f, a friend of M,
// not the definition of a member function
};
— end example ]


So, if I have well understood I could write such a short code:

# include <iostream>

class P
 {
  friend void friend_inline()
   {std :: cout << P :: Name << ' ' << p << '\n';}
  static constexpr int Name = 20;
  static constexpr double p = 12.5;

  };

int main()
 {
  P p;
  // how can I call friend_inline ?
}

which indeed is compiled by 4.8.3 g++ compiler. But the question is in the comment: I tried both the call as if friend_inline was in global scope (the standard said "global definition") and the call through the :: scope resolution operator such as

P :: friend_inline();

Neither worked. I also tried adding a public member to P as a "wrapper" of friend_inline (so making it and its friendship redundant), but the compiler claimed that friend_inline was undeclared in the class scope...

I can't understand...


                         Graziano Servizi






[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux