0% found this document useful (0 votes)
2 views9 pages

Understanding Multiple Inheritance in C++

Uploaded by

Guzar hussain
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

Understanding Multiple Inheritance in C++

Uploaded by

Guzar hussain
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Multiple inheritance

With Simple
Parameters
What is Inheritance?
Inheritance is an object-oriented programming concept in which one class
(child or derived class) inherits properties and behaviors (data members and
member functions) from another class (base or parent class).

Example:
class Animal {
public:
Output:
void eat() {
cout << "Eating..." << endl;
Eating...
}
Barking...
};
class Dog : public Animal {
public:
void bark() {
cout << "Barking..." << endl;
}
};
Multiple Inheritance!

Multiple Inheritance refers to a feature of C++ where a single derived class


can inherit from more than one base class.

Characteristics:

Multiple Base Classes One derived class inherits from two or more base classes.

Functions and data members of all base classes can be reused in the
Code Reusability derived class.
Increased Complexity As more base classes are added, the class hierarchy can become
harder to manage.
Base class constructors are called in the order they appear in the
Constructor Calling Order
inheritance list.
Occurs when two base classes inherit from a common base, and a
Diamond Problem derived class inherits from both
Syntax of Multiple Inheritance.
#include <iostream>
using namespace std;

class Writer {
public:
void write() { Output:
cout << "Writing content..." << endl;
}
};
Writing content...
Speaking to audience...
class Speaker { Publishing a book...
public:
void speak() {
cout << "Speaking to audience..." << endl;
}
};
class Author : public Writer, public Speaker {
public:
void publish() {
cout << "Publishing a book..." << endl;
}
};
int main() {
Author a;
[Link]();
[Link]();
[Link]();
return 0;
}
What are Parameters?
a parameter is a variable listed inside the parentheses of a function definition. It's used
to pass information into the function when it's called.

Syntax:

1. void greet(string name) {


2. cout << "Hello, " << name << "!" << endl;
3. }
Why are Parameters important?

1. They make functions flexible and reusable.


2. You can perform operations with different data
without rewriting the function.
Parameter vs Arguments.

Term Meaning
Parameter Variable in function definition (like name)
Actual value passed to the function (like
Argument
"Alice")

Example: #include <iostream>


using namespace std;

void add(int a, int b) { // a and b are parameters


cout << "Sum: " << a + b << endl;
}

int main() {
add(5, 3); // 5 and 3 are arguments
return 0;
}
Types of Parameters

1. Function Parameters

These are placeholders in a function definition.

Example:

void greet(string name) {

cout << "Hello, " << name << "!" << endl;
}
2:Arguments Parameter

1. These are the real values you pass when calling the function.

2. Example:
greet("Alice");
Good Bye.

[Link] Questions.

You might also like