Advertisement

I got a question

Started by April 24, 2002 08:06 PM
2 comments, last by unknownfriend 22 years, 10 months ago
How do you make the window code from tutorial 1 a header file so I can add it to all of my programs? Don''t flame me for asking this question, I looked all over the internet to find the answers. I even read the article that gamedev posted.
Actually, as I have been taught, it is not good practice to put function code in header files. You can, however, put function declarations in a header file (basically, the first line of the function plus a semicolon). Save the file as a header ("glwindow.h" for example). The reason for this is to tell the compiler that these functions are available.

Then, put the actually function code in another .cpp file, in this case, glwindow.cpp. Make sure this file contains all the necessary include files, including "glwindow.h" To access this code in your main program, add the new source file to the project.
Advertisement
So, I can just add my window.cpp file to my project and have a seperate main.cpp with only scene rendering code and compile it with no extra codes to add?
Almost, but no. You have to make a header file with the function declarations from your main.cpp and include this header in the window.cpp. NOW you can compile

err... I assume the WinMain function is in window.cpp. If not, include the function declarations and headers the other way round.



- An eye for an eye will make the world go blind -

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

This topic is closed to new replies.

Advertisement