PDA

View Full Version : Proper C++ Implementation


neptune3d
04-11-2006, 05:33 AM
Hello all,

Please forgive the basic question :)

I am a 2nd year Software Engineering Student at a local college starting to learn OpenGL. I have recently been using c and made the switch to c++ a few months ago but this is my first run into making windows proggries from scratch.

After making a few test apps I have decided to seperate my code to different files but am wondering if I am going too far. My Original thought was to have a main.cpp with only winmain, have the event handler off in its own .h/.cpp pair, a setup.cpp/.h pair that would register the class, pixelformat, etc and create the window and finally a displayFrame pair that would have all the rendering stuff.

My question is should I be seperating windows functions out to their own files or for implementation, standards, speed, etc, would it be best to keep them all in the same file?
(then I have to figure out why my handle isn't passing from one file to the next :) )

Thx all,
Nep

.oisyn
04-11-2006, 08:08 AM
It doesn't really matter with regards to the end result, so do what you're most comfortable with. Keep in mind that compilation times of larger files are longer of course, so a small change in a single file takes less project rebuild time than that very same change in a much larger file.

kyuzo
04-11-2006, 10:20 AM
Hello all,
My Original thought was to have a main.cpp with only winmain, have the event handler off in its own .h/.cpp pair, a setup.cpp/.h pair that would register the class, pixelformat, etc and create the window and finally a displayFrame pair that would have all the rendering stuff.


hi

i'm not sure i would go that far.
why dont break your problem in logical entities, and put them in separate files, something like: window.cpp, menu.cpp, scene.cpp, object3d.cpp etc.

neptune3d
04-11-2006, 10:25 AM
Thx folks,

The more I thought about it the more it made sense to create the window in area with all that good windows stuff with it, then create seperate functions in other files to use as reusable code for later.

Thx again.
Nep

monjardin
04-11-2006, 12:24 PM
You may want to research object oriented design (OOD) and organize your code into a hierarchy of classes. OOD (classes) and generic programming (templates) are the major additions from vanilla C. Well, having the STL and type-safe I/O (i.e., iostreams versus sprintf et al) are nice too, but they involve templates and classes!