I saw this code in a textbook and I tried to put in my eclipse IDE, but it didn't work:
#include "GradeBook.h"
#include <iostream>
using namespace std;
// GradeBook class definition
class GradeBook
{
public:
// function that displays a welcome message to the GradeBook user
void displayMessage()
{
cout << "Welcome to the Grade Book!" << endl;
} // end function displayMessage
}; // end class GradeBook
// function main begins program execution
int main()
{
GradeBook myGradeBook; // create a GradeBook object named myGradeBook
myGradeBook.displayMessage(); // call object's displayMessage function
} // end main
However, when I got rid of the header file declaration
#include "GradeBook.h"
the codes compiled properly.
The header file's content is:
#ifndef GRADEBOOK_H_
#define GRADEBOOK_H_
class GradeBook {
};
#endif
Why does this happen? And why do IDE's create header files? This confuses me, because I'm used to seeing a class declaration and putting codes within it. By including the header file I just write a whole bunch of codes. Do you guys all program with header files too?