Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ Multiple Inheritance

// Base class
class MyClass {
  public:
    void myFunction() {
      cout << "Some content in parent class." ;
    }
};

// Another base class
class MyOtherClass {
  public:
    void myOtherFunction() {
      cout << "Some content in another class." ;
    }
};

// Derived class
class MyChildClass: public MyClass, public MyOtherClass {
};

int main() {
  MyChildClass myObj;
  myObj.myFunction();
  myObj.myOtherFunction();
  return 0;
}
Comment

multiple inheritance c++

class A
{ 
... .. ... 
};
class B
{
... .. ...
};
class C: public A,public B
{
... ... ...
};
CPP
Comment

multiple inheritance c++

#include<iostream>
using namespace std;
 
class A
{
public:
  A()  { cout << "A's constructor called" << endl; }
};
 
class B
{
public:
  B()  { cout << "B's constructor called" << endl; }
};
 
class C: public B, public A  // Note the order
{
public:
  C()  { cout << "C's constructor called" << endl; }
};
 
int main()
{
    C c;
    return 0;
}
Comment

multiple inheritance c++

#include<iostream>
using namespace std;
class Person {
   // Data members of person
public:
    Person(int x)  { cout << "Person::Person(int ) called" << endl;   }
};
 
class Faculty : public Person {
   // data members of Faculty
public:
    Faculty(int x):Person(x)   {
       cout<<"Faculty::Faculty(int ) called"<< endl;
    }
};
 
class Student : public Person {
   // data members of Student
public:
    Student(int x):Person(x) {
        cout<<"Student::Student(int ) called"<< endl;
    }
};
 
class TA : public Faculty, public Student  {
public:
    TA(int x):Student(x), Faculty(x)   {
        cout<<"TA::TA(int ) called"<< endl;
    }
};
 
int main()  {
    TA ta1(30);
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ read_ascii 
Cpp :: std::hash 
Cpp :: labs c++ 
Cpp :: The Three Topics codechef solution in c++ 
Cpp :: 271533778232847 
Cpp :: copy constructor in c++ questions 
Cpp :: 01matrix 
Cpp :: C++ with SVD 
Cpp :: convert c to C language 
Cpp :: python Difference Array | Range update query in O(1) 
Cpp :: pass address to function c++ 
Cpp :: count substrings codechef solution in c++ 
Cpp :: Error: C++14 standard requested but CXX14 is not defined 
Cpp :: C++ Vector Initialization method 02 
Cpp :: cpp full form 
Cpp :: thread group c++ 
Cpp :: how to use printf with microseconds c++ 
Cpp :: bitmap rotate 90 deg 
Cpp :: Check if two stacks are the same using C++ 
Cpp :: check if an item is in a vector c++ 
Cpp :: Integer Literrals in C++ Programming 
Cpp :: inverse lerp c++ 
Cpp :: auto i cpp 
Cpp :: constants in cpp 
Cpp :: how to change the type of something in c++ 
Cpp :: how to put string in array c++ 
Cpp :: how to implement binders and decorators on c++ lik python? 
C :: What are the 3 basic types of Plate Boundaries? Explain their differences (how they act). 
C :: lewis hamilton 
C :: come creare variabili casuali in c 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =