Find greatest of two numbers in two different classes using friend function C++
greatest_friend.cpp.txt
File size: 497 Bytes
File content type: text/plain
Category: Practical Files
Subject: Object Oriented Programming
Download greatest of two numbers using friend function C++ generally taught in Object Oriented Programming.
#include<iostream>
using namespace std;
class B; //declare class B
class A {
private:
int a;
public:
//constructor
A(int a) {
this->a = a;
}
friend int max(A a, B b);
};
class B {
private:
int b;
public:
//constructor
B(int b) {
this->b = b;
}
friend int max(A a, B b);
};
int max(A a, B b) {
return (a.a > b.b ? a.a : b.b);
}
int main() {
A a(10);
B b(15);
cout << "Greatest is : " << max(a, b);
return 0;
}
Last Updated: July 16, 2022
Related
Thevenin's Theorem Experiment
Category: Practical FilesJuly 16, 2022
EHVACDC Unit 3
Category: NotesJuly 17, 2022
Solved Question Paper EHVACDC Akash
Category: Question PapersJuly 17, 2022
Introduction to Wireless Channels and Diversity (WC)
Category: NotesJuly 16, 2022
Three Ammeter Method
Category: Practical FilesJuly 16, 2022
IPU CA Notes Unit 3
Category: NotesJuly 16, 2022
P K Sinha FOC notes chapter 1-10
Category: eBooksJuly 16, 2022
Engineering Drawing ND Bhatt PDF
Category: eBooksJuly 16, 2022
Magnetic Circuits - Unit 4 - Handwritten Notes
Category: NotesJuly 16, 2022
IPU Introduction to Programming (ITP) Notes Full Semester
Category: NotesJuly 16, 2022