Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
deleted 13 characters in body; edited tags; edited title
Source Link
Roger Pate
Roger Pate

A basic understanding of the function of the C++ header files

added 116 characters in body
Source Link
Proclyon
  • 526
  • 5
  • 12

I have a theory question rather than an error report.

I'm a rookie C++ programmer, trying to promote that away

Using the VC++ VS2008 compiler

I am often finding myself wondering WHY I want to take some actions in header files.

For example look at this code block:

#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 hooked up CPP file , controller.cpp along 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 which includes go where? So far I've been going with the " whatever works" method but I find it somewhat unprofessional.

Now even though you can say my code has X syntax errors and design flaws, please do, but the focal point I would appreciate that information remains on the use of .h VS .cpp files.

Why is there even such a design? And what are the pits and traps to always be treading lightly around when making any kind of OOP based C++ program?

What sparked this question for me btw was that I wanted to notify the reader of the header file there will be objects stored in the controller but assigning these uninitialized objects seemed impossible without making them static.

Note: I stem from C# --> C++ , might help to know. That's kind of my perspective on code at this point.

Thank you in advance for you efforts!

EDIT: 26/08/2010 18:16

So the build time is the essence of good includes. Is there more to be cautious about?

I have a theory question rather than an error report.

I'm a rookie C++ programmer, trying to promote that away

Using the VC++ VS2008 compiler

I am often finding myself wondering WHY I want to take some actions in header files.

For example look at this code block:

#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 hooked up CPP file , controller.cpp along 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 which includes go where? So far I've been going with the " whatever works" method but I find it somewhat unprofessional.

Now even though you can say my code has X syntax errors and design flaws, please do, but the focal point I would appreciate that information remains on the use of .h VS .cpp files.

Why is there even such a design? And what are the pits and traps to always be treading lightly around when making any kind of OOP based C++ program?

What sparked this question for me btw was that I wanted to notify the reader of the header file there will be objects stored in the controller but assigning these uninitialized objects seemed impossible without making them static.

Note: I stem from C# --> C++ , might help to know. That's kind of my perspective on code at this point.

Thank you in advance for you efforts!

I have a theory question rather than an error report.

I'm a rookie C++ programmer, trying to promote that away

Using the VC++ VS2008 compiler

I am often finding myself wondering WHY I want to take some actions in header files.

For example look at this code block:

#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 hooked up CPP file , controller.cpp along 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 which includes go where? So far I've been going with the " whatever works" method but I find it somewhat unprofessional.

Now even though you can say my code has X syntax errors and design flaws, please do, but the focal point I would appreciate that information remains on the use of .h VS .cpp files.

Why is there even such a design? And what are the pits and traps to always be treading lightly around when making any kind of OOP based C++ program?

What sparked this question for me btw was that I wanted to notify the reader of the header file there will be objects stored in the controller but assigning these uninitialized objects seemed impossible without making them static.

Note: I stem from C# --> C++ , might help to know. That's kind of my perspective on code at this point.

Thank you in advance for you efforts!

EDIT: 26/08/2010 18:16

So the build time is the essence of good includes. Is there more to be cautious about?

Source Link
Proclyon
  • 526
  • 5
  • 12

A basic understanding of the function of the C++ header files

I have a theory question rather than an error report.

I'm a rookie C++ programmer, trying to promote that away

Using the VC++ VS2008 compiler

I am often finding myself wondering WHY I want to take some actions in header files.

For example look at this code block:

#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 hooked up CPP file , controller.cpp along 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 which includes go where? So far I've been going with the " whatever works" method but I find it somewhat unprofessional.

Now even though you can say my code has X syntax errors and design flaws, please do, but the focal point I would appreciate that information remains on the use of .h VS .cpp files.

Why is there even such a design? And what are the pits and traps to always be treading lightly around when making any kind of OOP based C++ program?

What sparked this question for me btw was that I wanted to notify the reader of the header file there will be objects stored in the controller but assigning these uninitialized objects seemed impossible without making them static.

Note: I stem from C# --> C++ , might help to know. That's kind of my perspective on code at this point.

Thank you in advance for you efforts!