Wednesday, October 6, 2010

Class declaration and definition

A class declaration is anything, essentially, that tells the compiler a name is for a class. For example;

C++ Syntax

class  ClassName;
is known as a "forward declaration".


A class definition is a type of declaration that provides enough information that a compiler can create instances of the class, compute sizeof() for the class, call member functions, and access data members of the class.

A class with "prototypes of member functions" is one type of class definition.

A class "with member functions defined in the class" is another type of class definition - the only difference is that it is a class definition with inline definitions of member functions.

Including header types

In C++ it's common to see two methods of including a header file:

#include
#include "filename"

The difference between the two varies on the compiler you are using, however the rule of thumb is that the first version, between the "<" and ">", will have the compiler search for filename in a series of predefined paths. It is the standard to use the #include form when including header files that are part of the C++ standard library, such as iostream or cstdlib.
The second form of including a header file is meant mostly for custom header files that are located in the same path as the C++ application itself