Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Container Class vs Class - C++

Tags:

c++

class

I'm new to programming and just come across this assignment

Create a container class family that holds an array of 20 person objects.

I have been looking on the internet as well as in my book, but I still can't figure out the difference between a Container Class and a Class in C++.

How could I create a family class and 20 person objects at the same time?

like image 408
Minh Le Avatar asked Dec 30 '25 21:12

Minh Le


1 Answers

"Container class" is not some official term; it's just the word "class" with an English describing word next to it. The assignment is asking you to create a class that contains some other stuff; namely, an array of 20 person objects.

At its most basic, the result could be as simple as this:

class family
{
public:
   person people[20];
};

In real life, you might do something like this instead:

#include <array>
using family = std::array<person, 20>;

It seems unlikely that every family (or even most families) has precisely 20 people in it, so I would personally end up just going with:

#include <vector>
std::vector<person> family;

… and manipulating the vector as appropriate.

like image 154
Lightness Races in Orbit Avatar answered Jan 02 '26 13:01

Lightness Races in Orbit