An example of a class declaration.
// definition file named listhead.h for list package typedef struct List_Item { int val; List_Item * next; } List_Item; class List_Head { List_Item* next; public: void insert(List_Item *); void printout(); }; // implementation file for the List_Head class #include "listhead.h" void List_Head::insert(List_Item * Item) { Item->next = next; next = Item; } void List_Head::printout() { List_Item * curr; curr = next; while(curr) cout << curr->val << '\n'; }
The implementation matches function declarations to the prototypes given inside the class body. It prefixes the name of each function with the class name to which it is bound followed by a double colon. Before a class object can be created, implementations must be provided for all its functions.