// 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;
}
class A
{
... .. ...
};
class B
{
... .. ...
};
class C: public A,public B
{
... ... ...
};
CPP
#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;
}
#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);
}
Code Example |
---|
Cpp :: inline c++ |
Cpp :: c++ program to generate all the prime numbers between 1 and n |
Cpp :: c++ #define |
Cpp :: pointer cpp |
Cpp :: c++ access second last element of vector |
Cpp :: attention nlp |
Cpp :: vector iterating |
Cpp :: resize string c++ |
Cpp :: c++ random number |
Cpp :: c++ set swap |
Cpp :: inheritance in c++ |
Cpp :: unpack tuple c++ |
Cpp :: c++ vector first element |
Cpp :: abstraction in cpp |
Cpp :: Fisher–Yates shuffle Algorithm c++ |
Cpp :: find positive number factorial in C++ |
Cpp :: converting decimal to binary in cpp |
Cpp :: max pooling in c++ |
Cpp :: makefile for single cpp file |
Cpp :: c++ polymorphism |
Cpp :: opencv compile c++ |
Cpp :: read a whole line from the input |
Cpp :: c ++ program to insert into hashmap |
Cpp :: DS1302 |
Cpp :: C++ Vector Operation Access Elements |
Cpp :: new in c++ |
Cpp :: Valid Parentheses leetcode in c++ |
Cpp :: flutter text direction auto |
Cpp :: char at in c++ |
Cpp :: Initialize Vector Iterator with end() function |