0 Bewertungen0% fanden dieses Dokument nützlich (0 Abstimmungen)
140 Ansichten9 Seiten
FRIEND FUNCTIONS to swap two numbers using Friend Function #include class two; class one int value1; public: void indata(int a) value1 = a; void display(void) cout value2 ; friend void exchange (one &, two &); ; ; to calculate the total salary of the family using Friend Function class Wife; class Husband private: long salary;
FRIEND FUNCTIONS to swap two numbers using Friend Function #include class two; class one int value1; public: void indata(int a) value1 = a; void display(void) cout value2 ; friend void exchange (one &, two &); ; ; to calculate the total salary of the family using Friend Function class Wife; class Husband private: long salary;
Copyright:
Attribution Non-Commercial (BY-NC)
Verfügbare Formate
Als PPT, PDF, TXT herunterladen oder online auf Scribd lesen
FRIEND FUNCTIONS to swap two numbers using Friend Function #include class two; class one int value1; public: void indata(int a) value1 = a; void display(void) cout value2 ; friend void exchange (one &, two &); ; ; to calculate the total salary of the family using Friend Function class Wife; class Husband private: long salary;
Copyright:
Attribution Non-Commercial (BY-NC)
Verfügbare Formate
Als PPT, PDF, TXT herunterladen oder online auf Scribd lesen
Type friend class Classname in class granting friendship If ClassOne granting friendship to ClassTwo, friend class ClassTwo; appears in ClassOne's definition
Program to illustrate friend classes in C++
#include <iostream> class CSquare; class CRectangle { int width, height; public: int area ( ) {return (width * height);} void convert (CSquare a); }; }; void CRectangle::convert (CSquare a) { width = a.side; height = a.side; } class CSquare { private: int side; public: void set_side (int a) {side=a;} friend class CRectangle;
Program to illustrate friend classes in C++
int main ( ) { CSquare sqr; CRectangle rect; sqr.set_side(4); rect.convert(sqr); cout << rect.area( ); return 0; }