- Header file needs macro guard (by preprocessor
directives) which wraps the class definition. They are need to avoid
duplicate definition.
// filename: myclass.h
// macro guard
#ifndef MYCLASS_H
#define MYCLASS_H
class MyClass
{
...
};
#endif // end of macro guard
- Implementation file needs to #include the header file. For user
defined header file, you enclose it by " ".
// filename: myclass.cpp
#include "myclass.h" // include header file
MyClass::MyClass()
{ ... }
- Application file must #include the header file(s) of the class(s).
// filename: app1.cpp
#include <iostream>
using namespace std;
#include "myclass.h" // include header file
int main()
{
...
return 0;
}