Modules

Q: why do we want to be able to decompose out program sinto multiple source files?

  1. allows work to be done independently and in parallel
  2. allows recompilation of only what changed, and then re-link
  3. makes it easier to reuse components
  4. makes it easier to evolve code (i.e: change implementation, retain same interface)

Declarations vs Definitions

Declarations: tell the compiler of a name of a type, constatnt, class, etc...

- if the compiler cannot find a declaration, compilation will grid to a halt
- can be repeated

Definitions: tell the compiler the ammount of space to allocate, what ADT methods exist, their signatures, etc...

- there can be _only one_ definition, or else compilation will fail

Rule of Thumb: prefer declarations (as in forward declarations) over definitions where you can.

Also, DON'T EVER PUT using namespace std; IN YOUR HEADER FILES!

Program Decomposition - See Slides, lot's of diagrams

Forward Declarations

Q: when do we actually need forward declarations?

  • Whenever the compiler needs to know the ammount of space to allocate.
    • Including ADT 1 in ADT 2, and ADT 2 in ADT 1
      • Can be fixed by using a pointer
    • Inheritance class A : public B { ... }, how big is b
      • Unfixable, must use forward declarations
    • Inlining Code: class C { A a; public: void foo(){ a.bar() }}
      • Can be fixed by seperating declarations and definitions.

Make and Partial Compilation - See Slides

results matching ""

    No results matching ""