Computer Science, asked by hardikaryan106, 4 days ago

Write a program in c++ to demonstrate use of Friend function?​

Answers

Answered by pkb032497
3

Answer:

Let's see the simple example of C++ friend function used to print the length of a box.

#include <iostream>

using namespace std;

class Box.

{

private:

int length;

public:

Box(): length(0) { }

Explanation:

hope it helps you mark me as brainlist and drop some thanks and follow also

Answered by omkardengi08
0

#include<iostream.h>

using namespace std;

class temp

{

int a, b, add;

public:

void input()

{

cout << "Enter the value of x and y:";

cin >> x>>y;

}

friend void add(temp &t);

void display()

{

cout << "The sum is :" << z;

}

};

void add(temp &t)

{

t.add = t.a + t.b;

}

int main()

{

temp t1;

t1.input();

add(t1);

t1.display();

return 0;

}

Similar questions