What is multiple inheritance? - C++

What is multiple inheritance?

- When a class is derived from another class ie it inherits functionalities of another class, this phenomenon is known as inheritance. In some cases, a class can inherit from multiple classes, ie a derived class can have multiple base classes, it is known as multiple inheritance.
- Consider the following example :
class Base1
{
   private:
       int no1;
   public:
       void show1()
       {
          cout << “The number is:” << no1 <<”\n”;
       }
};

class Base2
{
   private:
       int no2;
   public:
       void show2()
       {
          cout << “The number is:” << no2 <<”\n”;
       }
};
class Derived: public Base1, public Base2 //Multiple inheritance
{
   public:
       void set(int x, int y)
       {
          no1 = x; no2 = y;
       }
};

int main()
{
   Derived ob;
   ob.set(10, 20);
   ob.show1();    // Derived class obj can access member functions of both base classes
   ob2.show2();    //Derived class obj can access member functions of both base class return 0;
}
What are the syntax and semantics for a function template? - C++
Function template - Templates is one of the features of C++. Using templates, C++ provides a support for generic programming....
Differentiate between a template class and class template - C++
Differentiate between a template class and class template - Template class: A class that has generic definition or a class with parameters which is not instantiated until the information is provided by the client...
What is function template?
What is function template? - Function template defines a general set of operations that will be applied to various types of data....
Post your comment
Discussion Board
wrong
you declared no1 and no2 in private
then how can you access that in sent function ....
i think u have to declare in protected , then only it will run without compiler err..
indhiravelu 06-16-2017