Preparing to write a die game.
Objectives
We would like to :
- Review header files
- Review implementation files
- Review using these
- Review file linking
Notes
- To make something reusable, you need it to be in separate files.
- What is a header file and what goes into it
- no executable code
- type definitions (structs)
- function prototypes
- Some constant definitions
- Only things that need to be shared.
- What are guards and what do they do?
- Should
-
using namespace std;
be in a .h file?
- How about includes?
- Take a look at die.h
- What goes in an implementation file?
- I usually include the corresponding header file.
- Notice this is done with "" and not <>
- I usually include iostream, is this ok?
- I usually add
using namespace std
is this ok?
- Directives like include and using do not cross compiling boundaries, so they do not impact other code.
- Take a look at die.cpp
- How do I include these in code with a main?
- Take a look at task4pre.cpp
- How do I compile this?
- You need to tell make that if die.h changes, die.o needs to be recreated.
- This is called a dependency
-
die.o: die.h
- It knows that die.o depends on die.cpp, so that is not required.
- You also need to tell it that task4pre depends on die.o
-
task4pre : die.o
- Look at the Makefile.