c++ - Can a private member function of class A be declared as a friend of class B? -


lippman's essential c++ section 4.7 this. don't know why code not compile:

#include <iostream> using namespace std;  class {    void f(); //other members... };  class b { //other members... friend void a::f(); };  int main() { return 0; } 

while putting "public:"before void f() in class compiles. lippman wrong?

p.s. lippman's code this:

//... class triangular_iterator { //... private: void check_integrity() const; //... };  //...  class triangular { //... friend void triangular_iterator::check_integrity(); //... };  //... 

you cannot declare function or members of "class a" friend of "class b" in "class b".
must allow "class b" friend of "class a"'s, , make a::f() friend of "class b"'s:

class {    void f();  friend class b; //allow b access private (protected) members , functions };  class b { friend void a::f(); }; 

in real life, can't determine someone's friend against will, either!

see here example.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -