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
#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