Basic understanding of C ++ header files

I have a theory question, not a bug report.

I am a new C ++ programmer trying to promote this.

Using the compiler VC ++ VS2008

It often seems to me that I am wondering WHY I want to take some action in the header files.

For example, look at this block of code:

#include "DrawScene.h"
#include "Camera.h"
#include "Player.h"
#include "Grid.h"
#include "InputHandler.h"
#include "GameState.h"

class Controller
{
public:
private:
public:
 Controller();
 ~Controller(){}
 void Update();

private:
};

And the attached CPP file, controller.cpp with it

#include "stdafx.h"
#include "glut.h"
#include "Controller.h"
#include <iostream>

Grid* grid_ptr = new Grid();
InputHandler* inputHandler_ptr = new InputHandler();
DrawScene* drawScene_ptr = new DrawScene();
GameState* gameState_ptr = new GameState();

Controller::Controller()
{

}

void Controller::Update()
{

}

What is a good way to decide where to include? So far, I have come with the “everything that works” method, but I consider it somewhat unprofessional.

Now, even if you can say that my code contains X syntax errors and design flaws, do it, but coordinator, I would appreciate that the information is left behind using .h VS.cpp files.

? , - ++ ?

, , , , , .

: # → ++, . .

!

EDIT: 26/08/2010 18:16

, - . ?

+5
5

cpp. (, , 3- ) . , , cpp.

. , , , . , cpp, .

forward PIMPL ( IMPLementation opaque pointer). / . :

// header file:
class SomeType;

class AnotherType
{
private:
    SomeType *m_pimpl;
};

, "sometype.h" , :

// header file
class AnotherType
{
private:
    SomeType m_impl;
};

. EDIT: "sometype.h" "anothertype.h" , "sometype.h" "anothertype.h" cpp , "anothertype.h" .

cpp. - , , include?

+4

, , : , . , , .

++ ( #, iiuc) . , , , , .

+15

, . , . , . DrawScene, GameState, Grid InputHandler , .

, ++ . , . , - , .

+4

(, ) #includes .h . , . , Camera.h, Controller.h, , Controller.h, . , .

, -, #includes cpp.

.h .cpp , . , , , , , , , .

++ inline , , Java, / .h/.cpp.

+3

, , cpp .

. ++, , .. , .

cpp . , , / , , .

+2

All Articles