// Timer.hclass Timer{ public: Timer(); void member_function(); // constructor, destructor, member function declarations private: int member_variable; // member variables};// Timer.cpp#include "Timer.h"Timer::Timer(){ // implementation}void Timer::member_function(){ // implementation}// etc.// Shape.hclass Shape{ public: Shape(); std::vector<SDL_Rect>colBox_ball; std::vector<SDL_Rect>colBox_ppaddle; std::vector<SDL_Rect>colBox_cpaddle; // etc.};// Shape.cpp#include "Shape.h"Shape::Shape(){ // implementation}// etc.// Tradjectory.h#include "Shape.h"// forward declarationclass PaddleC;class Tradjectory : public Shape{ public: Trajectory(Shape * to); void center_cpu_paddle_colbox(PaddleC & CpuPaddle); // etc.};// Tradjectory.cpp#include "Tradjectory.h"#include "PaddleC.h"Tradjectory::Tradjectory(Shape * to){ // implementation}void Tradjectory::center_cpu_paddle_colbox(PaddleC & CpuPaddle){ // implementation}// etc.// PaddleC.hclass PaddleC : public Shape{ public: // etc.};// PaddleC.cpp#include "PaddleC.h"// etc.// etc. // main.cpp#include "Tradjectory.h"#include "PaddleP.h"#include "PaddleC.h"#include "Ball.h"int main(){ Trajectory theTraj; PaddleP PlayPaddle; PaddleC CpuPaddle; Ball GameBall; CpuPaddle.applyVelocity(); theTraj.center_cpu_paddle_colbox(CpuPaddle);}
Each class is separated into a header file and an implementation file. Header files contain class defintions. Implementation files contain member function definitions. Each header file #includes the header file for any class its class inherits from or contains a member of. Each header file forward declares any class it mentions as a parameter but does not use. Each implementation file #includes its header file plus the header file of any class it uses.
Σnigma