The implementation file in C++ Programming:-

The implementation file contains the definition of all the methods of a class –what each one of these amounts to is, in fact, a very small C++ program. The file will almost certainly be required to have the same extension as C++ programs on your system, so you’ll need to quickly check your Local guide for confirmation and details.

As with any C++ program, the implementation file starts with a header block of comments describing the purpose of the class and giving the name of the author, the date of writing and the platform. Any system libraries that are used in any of the methods are also included at the top, as is the header file containing the definition of the class to be implemented. Finally, the line:

using namespace std;

as usual tells the compiler that the methods will use the standard C++ names and functions.

You should by now have a template file for your C++ programs, and it is probably a sensible idea to create a copy and adapt it slightly as a template for your implementation files. It might look like this:

// class.cc
//
// Implementation of the < ... > class.
//
// Class to ...
//
// Author: AMJ
// Date:
// Platform:

#include <iostream>

#include "class.h"

using namespace std;

As a completed example, an implementation file containing the definition of a class to contain the methods for the Sheep class would start:

// sheep.cc
//
// Implementation of the Sheep class.
//
// Demonstrates the basic structure of a C++
// implementation file.
//
// Author: AMJ
// Date: 27th November 2001
// Platform: g++, Linux

#include <iostream>
#include <string> // Sheep's name is a string

#include "sheep.h"

using namespace std;

The remainder of the file contains the definitions of the methods, one at a time. It is usual for them to be implemented in the same order as they appear in the header file (it makes them easier to find when changes need to be made or problems need to be fixed), so the constructor is normally written first.