Challenge: Container Class with Multiple Destructors

Let’s try to implement the Container class with multiple destructors.

We'll cover the following

Problem

Implement the destructor of a partially written class Container that has two data members: an array t of template type T, and its length given by size. As we can see, in the constructor, t, is being initialized with dynamic memory, so it should be deallocated in the destructor.

The task is to implement the multiple destructors for Container class using std::is_trivially_destructible_v.

We should print to the console “Trivial” or “Not trivial” inside the destructor based on the requirement.

After you implement the destructors, uncomment the lines from the main function to see the output.

Try it yourself first. If you have trouble getting to the solution, you can always press the “Show Solution” button to see how the problem can be solved. We’ll go through the in-depth solution in the next lesson.

Good luck!

Get hands-on with 1400+ tech skills courses.