friend function in c++
C++
#include <iostream>
class B;
class A {
public:
void showB(B&);
};
class B {
private:
int b;
public:
B() { b = 0; }
friend void A::showB(B& x); // Friend function
};
void A::showB(B& x)
{
// Since showB() is friend of B, it can
// access private members of B
std::cout << "B::b = " << x.b;
}
int main()
{
A a;
B x;
a.showB(x);
return 0;
}
Also in C++:
- Title
- factorial in c++
- Category
- C++
- Title
- power c++
- Category
- C++
- Title
- c++ clear console
- Category
- C++
- Title
- convert int to string c++
- Category
- C++
- Title
- pair in c++
- Category
- C++
- Title
- c++ declare char
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- append string to another string c++
- Category
- C++
- Title
- queue c++
- Category
- C++
- Title
- how to print a string to console in c++
- Category
- C++
- Title
- c++ code to print hello world
- Category
- C++
- Title
- file objects in c++
- Category
- C++
- Title
- range of long long in c++
- Category
- C++
- Title
- shortest path with bfs in c++
- Category
- C++
- Title
- char* to int in cpp
- Category
- C++
- Title
- c++ find prime numbers
- Category
- C++
- Title
- array<string, 7> c++
- Category
- C++
- Title
- deque c++
- Category
- C++
- Title
- insert function in c++ vector
- Category
- C++
- Title
- range based for loop c++
- Category
- C++
- Title
- c++ ternary operator
- Category
- C++
- Title
- cin.fail()
- Category
- C++
- Title
- binary tree search
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- registering a new QML type
- Category
- C++
- Title
- c++ char if
- Category
- C++
- Title
- variabili in c++
- Category
- C++
- Title
- body parser
- Category
- C++
- Title
- c++ menu selection with arrow keys
- Category
- C++
- Title
- delete a double pointer c++
- Category
- C++
- Title
- pointer related problems dangling/wild pointers c++
- Category
- C++
- Title
- two elements with difference K in c++
- Category
- C++
- Title
- loop c++
- Category
- C++
- Title
- swapo algorit
- Category
- C++
- Title
- how to find the mode of a vector c++
- Category
- C++
- Title
- struct c++
- Category
- C++
- Title
- c++ string to int
- Category
- C++
- Title
- memset
- Category
- C++
- Title
- how to delete something in an array c++
- Category
- C++
- Title
- how to measure program run time in c++
- Category
- C++
- Title
- apple and orange hackerrank solution in c++
- Category
- C++
- Title
- c++ vector lower_bound index
- Category
- C++
- Title
- how to get os name in c++
- Category
- C++
- Title
- create a 2d array c++
- Category
- C++
- Title
- c++ sort vector of objects by property
- Category
- C++
- Title
- how read a shader from another file c++
- Category
- C++
- Title
- c++ code for polynomial addition
- Category
- C++
- Title
- system("pause") note working c++
- Category
- C++
- Title
- graph using djacency matrix c++
- Category
- C++
- Title
- appending a double to a string c++
- Category
- C++
- Title
- how to convert int to string c++
- Category
- C++
- Title
- random number in c++
- Category
- C++
- Title
- time conversion hackerrank solution in c++
- Category
- C++
- Title
- pass by reference c++
- Category
- C++
- Title
- clear qlayout
- Category
- C++
- Title
- how to make a heap using stl in c++
- Category
- C++
- Title
- c++ triple
- Category
- C++
- Title
- intersection between vector c++
- Category
- C++
- Title
- placement new c++
- Category
- C++
- Title
- memcmp in cpp
- Category
- C++
- Title
- c++ how to loop through a vector but not the last element
- Category
- C++
- Title
- filling 2d array with 0 c++
- Category
- C++
- Title
- switch case sinax c++
- Category
- C++
- Title
- border radius layout android xml
- Category
- C++
- Title
- what is difference between ciel and floor
- Category
- C++
- Title
- else if c++
- Category
- C++
- Title
- max heap c++ stl;
- Category
- C++
- Title
- c++ cli convert string to string^
- Category
- C++
- Title
- c++ sort array of ints
- Category
- C++
- Title
- c++ looping through a vector
- Category
- C++
- Title
- fail() in c++
- Category
- C++
- Title
- int random string generator c++
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- building native binary with il2cpp unity
- Category
- C++
- Title
- prims c++
- Category
- C++
- Title
- min in vector c++
- Category
- C++
- Title
- pyqt connect
- Category
- C++
- Title
- c++ string contains
- Category
- C++
- Title
- create new file c++
- Category
- C++
- Title
- sort a string alphabetically c++
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- getline not working c++
- Category
- C++
- Title
- unordered_map c++
- Category
- C++
- Title
- case label in c++
- Category
- C++
- Title
- pairs in c++
- Category
- C++
- Title
- how to get input from the console in c++
- Category
- C++
- Title
- object slicing in c++
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- how to iterate trough a vector in c++
- Category
- C++
- Title
- initialize int c++
- Category
- C++
- Title
- Merge k sorted linked lists and return it as one sorted list.
- Category
- C++
- Title
- initialize array c++
- Category
- C++
- Title
- how to check sqrt of number is integer c++
- Category
- C++
- Title
- sum of two numbers c++
- Category
- C++
- Title
- tuple c++
- Category
- C++
- Title
- vertical traversal of binary tree
- Category
- C++
- Title
- how to use a new node c++
- Category
- C++
- Title
- va_arg
- Category
- C++
- Title
- fmod c++
- Category
- C++
- Title
- std::substring
- Category
- C++