.h
file contents form (for the most part) the interface
.cpp
file comprises the implementation
#include
of file.h
in the file file.cpp
.h
and .cpp
files in sync
Suppose we have
main.cpp
array.h
array.cpp
array.cpp
(compilerarray.cpp)
array.h
Array
) for scope resolution (Array::)
main.cpp
main.cpp
(compilermain.cpp)
array.h
Array
object, when main.cpp contains an Array
declaration
Array
when main.cpp
calls an Array
function
array.cpp
main.o
and array.o
Adding a #Include Guard (Macro Guard)
.h
file
class C { ... }; ... class C { ... };is illegal.
file student.h ... #include "array.h" // for the array of courses below ... class Student { ... private: ... Array courses(100); }; ------------------ file main.cpp ... #include "student.h" // We're a student application #include "array.h" // For the array of students below ... Array student(1000); ...The above code has the same duplicate class definition problem
_H
#ifndef ARRAY_H // if ARRAY_H has not already been defined #define ARRAY_H // define it ... #endif