Book Image

Learning C++ by creating games with UE4

By : William Sherif
Book Image

Learning C++ by creating games with UE4

By: William Sherif

Overview of this book

Table of Contents (19 chapters)
Learning C++ by Creating Games with UE4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Variables and Memory
Index

Putting your classes into headers


So far, our classes have just been pasted before main(). If you continue to program that way, your code will all be in one file and appear as one big disorganized mess.

Therefore, it is a good programming practice to organize your classes into separate files. This makes editing each class's code individually much easier when there are multiple classes inside the project.

Take class Mammal and its derived classes from earlier. We will properly organize that example into separate files. Let's do it in steps:

  1. Create a new file in your C++ project called Mammal.h. Cut and paste the entire Mammal class into that file. Notice that since the Mammal class included the use of cout, we write a #include <iostream> statement in that file as well.

  2. Write a " #include Mammal.h" statement at the top of your Source.cpp file.

An example of what this looks like is shown in the following screenshot:

What's happening here when the code is compiled is that the entire Mammal class...