TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How To Use Multiple Inheritance In C++
Logesh Palani
Aug 16
2016
Code
725
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
#include<iostream.h>
using
namespace
std;
// base class
class
Shape
{
public
:
void
setWidth(
int
w)
{
width = w;
}
void
setHeight(
int
h)
{
height = h;
}
protected
:
int
width;
int
height;
};
class
PaintCost
{
public
:
int
getCost(
int
area)
{
return
area * 70;
}
};
// Derived class
class
Rectangle:
public
Shape,
public
PaintCost
{
public
:
int
getArea()
{
return
(width * height);
}
};
int
main(
void
)
{
Rectangle a;
int
area;
a.setWidth(5);
a.setHeight(7);
area = a.getArea();
cout <<
"Total area: "
<< a.getArea() << endl;
cout <<
"Total paint cost: $"
<< a.getCost(area) << endl;
return
0;
}
Output
Total area: 35
Total paint cost: $2450
C++
Inheritance In C++