Hallo Richard,
>
> I'm a bit confused as to why, in any examples I see, a
> main.cpp file uses #include "MyClass.h": shouldn't the
> main.cpp file require both the class declaration and
> its definition?
>
the compiler needs to know the class declaration to generate a function
call. If you call a function (don't matters if it is in a class or not), the
compiler needs to know how many arguments from which type in which order
must be pushed onto the stack before the call. The compiler will generate
code that does this. Then the compiler will generate the code actually does
the call. Finally, the compiler must know the return type from the function
in order to generate code that pops it off the stack. The compiler doesn't
need to know the function definition to generate a function call.
chris
|