Creating a base component

With the theory covered, let's implement this into our project. The overwhelming message of this chapter has so far has been to use components to avoid messy inheritance, but we still need some inheritance as we need to use polymorphism!

Each object will be able to hold a range of components so we'll store them in a single generic container. In order for us to do this we need to make use of polymorphism, ensuring that all components inherit from a common base class. That base class is what we're going to implement now.

Let's add a new class to the project and call it Component. We'll leave it to you to implement the .cpp:

#ifndef COMPONENT_H #define COMPONENT_H class Component { public: /** * Default Constructor. */ Component(); ...

Get Procedural Content Generation for C++ Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.