• Related Questions & Answers

Containership in C++

C++Server Side ProgrammingProgramming

In this tutorial, we will be discussing a program to understand containership in C++.

The parameter if a certain class contains another class is called as containership. The inside class is called contained class, while the class in which it is present is called container class.

Example

 Live Demo

#include <iostream>
using namespace std;
class first {
   public:
   first(){
      cout << "Hello from first class\n";
   }
};
//container class
class second {
   first f;
   public:
   //constructor
   second(){
      cout << "Hello from second class\n";
   }
};
int main(){
   second s;
   return 0;
}

Output

Hello from first class
Hello from second class
raja
Published on 12-Mar-2020 06:07:41
Advertisements