Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ friend class

class A {
  	private:
      	int key;

 	// give class B access to class A
    friend class B;
};

class B {
	// new object from class A
  	A new_a;
  
  	void fn(){
		// access private value from class B
		new_a.key;
    }
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #friend #class
ADD COMMENT
Topic
Name
6+2 =