Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Main.h????

Author
Message
Kerl
User Banned
Posted: 27th Mar 2012 07:48
In reorganizing my current project, I decided to move several functions from my main.cpp into a new class in a completely different .cpp. The problem arose when the methods in this class try to use an enum that is set up in the main.cpp. My enum is now split between the main.cpp and myClass.cpp. Is there any way to use the enum from the main.cpp? It says GameStates (my enum) not declared. It sounds stupid but could I fix that by declaring the enum in a main.h file?
Fallout
17
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 27th Mar 2012 09:53
Define your enum in myClass.h, if that makes the most sense, and make it public.



Include myClass.h in your main.cpp. Refer to your enum with myClass::BOB::blah1, from main.cpp, and just BOB::blah1 from myClass.cpp.

Kerl
User Banned
Posted: 28th Mar 2012 08:36
Thanks for the reply!
I wasn't sure if the main.cpp was a sacred file in which no header files should be created to go along with it :p Just one of those general coding standards I figured I would ask about.
Fallout
17
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 28th Mar 2012 13:15
To be honest, I'm learning C++ right now, but I've been coding OO for years in other languages. I've had similar "Can I do that?" moments, but I just plough on and see if it works. Header files are nothing more than content that gets bolted to the top of whatever includes them. So anything you write at the top of your main.cpp file (e.g. enums, function definitions etc) can just be moved to a .H file and included.

WLGfx
12
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 29th Mar 2012 00:35
main.cpp isn't a 'sacred' file. DGDK handles that bit fore you as it has it's own single entry point unlike general C/C++ coding where you have main(), winmain(), etc...

Every .cpp file gets compiled just like your 'main' so all the .h files get included only as references to variables and functions from those other .cpp files, just like forward referencing. They just get thrown into another 'object' file for the linker to handle.

In general:

.h references to everything
.cpp the code (which will get linked)

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2020-02-26 05:53:07
Your offset time is: 2020-02-26 05:53:07