//Skip to content
Friend function in C++
- #include<iostream>
- using namespace std;
-
- class Shape;
-
- class Area{
- public:
- void getArea(Shape obj);
- };
-
- class Shape{
- private:
- int length;
- int width;
- int height;
- public:
- Shape(int a,int b,int c){
- length=a;
- width=b;
- height=c;
- }
- friend void Area::getArea(Shape obj);
- };
-
- void Area::getArea(Shape obj){
- cout<<"Area: "<<obj.length*obj.width<<endl;
- }
-
- int main()
- {
- Shape shape(3,4,5);
- Area area;
- area.getArea(shape);
- return 0;
- }
I am Md Abdullah Al Hasan. I have completed my graduation in Computer Science and Engineering from Jashore University of Science and Technology.
0 Comments:
Post a Comment