#ifndef STACK_H
#define STACK_H
class Stack { ... };
#endif
Sometimes this will not be enough, and you will have a circular
dependency. For example, you might have a .h file that
uses a definition from one .h file, but also defines something
needed by that .h file. In this case, you will have to do
something ad-hoc. One thing to realize is that you don't always
have to completely define a class before it is used. If you
only use a pointer to class Stack and do not access any
member functions or data from the class, you can write, in lieu of
including stack.h:
class Stack;This will tell the compiler all it needs to know to deal with the pointer. In a few cases this won't work, and you will have to move stuff around or alter your definitions.
Assertions are particularly useful at the beginnings and ends of procedures, to check that the procedure was called with the right arguments, and that the procedure did what it is supposed to. For example, at the beginning of List::Insert, you could assert that the item being inserted isn't already on the list, and at the end of the procedure, you could assert that the item is now on the list.
If speed is a concern, ASSERTs can be defined to make the check in the debug version of your program, and to be a no-op in the production version. But many people run with ASSERTs enabled even in production.
Perhaps more importantly, module tests provide an opportunity to find as many bugs as possible in a localized context. Which is easier: finding a bug in a 100 line program, or in a 10000 line program?