arissa_nightblade![]() Member Posts: 70 From: Registered: 02-10-2007 |
Hey! I'm getting a programming test for a potential job interview and I need to brush up on my C++ skill before then. I understand the basic concept of things like libraries and such, but I just want to make sure I'm 100% in everything. I've worked with 3D Game Studio a lot as of late, so I'm used to some of the Lite-C syntax which is a little different than C++. Just some basic newbie questions: For example: If I have a file called "maingame.h" and I include libraries inside this file such as: "#include player.h" I can use all the same variables and things I declared in the player.h file in maingame.h? What if I make a file called gamestart.cpp and I use #include "maingame.h" inside it? does this mean I can use variables I declared from both maingame.h and player.h? or am I just limited to stuff used in maingame.h only? I just want to know if C++ works the same as 3DGS's C-Scripting concept-wise. I realize the syntax will be different, but if the concept is still there, then I guess I won't have too much problem. The test is supposed to be in C++, so that's why I was worried. There are some libraries I'm not sure about, but I know they are needed. I already know about iostream.h, but I've seen stdio.h and stdlib.h used in a lot of programs, but I'm not sure why it's needed. Does anyone know of any sample C++ games that I can study from and see how things are done? Thanks in advance @_@ Sorry if this post sounds confusing... ------------------ |
|||
arissa_nightblade![]() Member Posts: 70 From: Registered: 02-10-2007 |
Also, what is the difference between putting something in a .h file than putting something in a .cpp file? Suppose I have a file called player.h and one called player.cpp. If I was making a game, I would put the attributes in things for a player character in the player.h file, right? so what would the player.cpp file be used for? or is player.h nothing more than just -defining- the attributes in there (like putting stuff like "float player_size," "char player_name," etc...) Yes, I'm stressing over this test >.> ------------------ |
|||
samw3![]() Member Posts: 542 From: Toccoa, GA, USA Registered: 08-15-2006 |
I can't explain it all right now, but it would do you well to understand the actual c compilation process. The C Preprocessor is what deals with .h files and any line that starts with # http://en.wikipedia.org/wiki/C_preprocessor ------------------ |
|||
Briant![]() Member Posts: 742 From: Stony Plain, Alberta, Canada Registered: 01-20-2001 |
OK, here's a simple break-down: .h file: a "header" file, should only contain things like function [u]declarations[/u] (i.e. the function "prototypes", i.e. the explanations of what functions are available), common #defines, etc. Don't put definitions (implementations) in an .h file, so that multiple .cpp files can #include the same .h file without ending up with multiple copies of function bodies and variables (which modern compilers will complain about anyway). I.e. this is why you don't #include any .cpp files (well, you can if you know what you're doing, but DON'T because you know what you're doing. .cpp file: an "implementation" file, contains the function [u]definitions[/u] (i.e. implementations, i.e. function bodies) of the functions declared in the corresponding .h file, global variables, etc. You can also put declarations here as well, but other .cpp files will be unable to see them. .lib file: a "library" file, is a compiled/linked binary file made up of one or more third-party .cpp files (containing their function bodies, etc.) For example: TheirHeader.h
MyApp.h
MyApp.cpp
When you compile/link your program, you'll have to make sure that their .lib file (TheirLib.lib or whatever) is linked in, so that when you call "TheirFunction1()" it knows what to do. Similarly, if you later make a "MyApp2.cpp" file, you can simply #include "MyApp.h" to have GOOD and BAD defined, and know about and thus call MyFunction1 and MyFunction2. Let me know if that helps, and if you have other questions.
Check out this webhost! Fantastic prices, features and support! [This message has been edited by BrianT (edited October 17, 2007).] |
|||
Briant![]() Member Posts: 742 From: Stony Plain, Alberta, Canada Registered: 01-20-2001 |
quote: Yes, include files (.h files) are nestable like that. You can think of "#include fred.h" as telling the precompiler to "take the contents of the whole fred.h and pretend it's all right here in this .cpp file instead". So if fred.h includes wilma.h, and wilma.h includes betty.h, you get betty and wilma by including fred. ------------------ Check out this webhost! Fantastic prices, features and support! [This message has been edited by BrianT (edited October 17, 2007).] |
|||
arissa_nightblade![]() Member Posts: 70 From: Registered: 02-10-2007 |
Thanks so much! It sounds a lot like the C-script, then! ^_^ I just have one question in regards to one of your examples. In the Myapp.h and Myapp.cpp, why do you define int MyFunction1() twice?? I thought once you define a function you don't have to define it again as long as you include the .h file that has it in there. Wouldn't you declare Myfunction in the MyApp.cpp one instead? I'm just wondering why you do that. I thought prototype functions were functions that had the & symbol in them and those would be the ones oyu would have to predefine? (ie: "myFunction(&test)" ) [This message has been edited by arissa_nightblade (edited October 17, 2007).] |
|||
Briant![]() Member Posts: 742 From: Stony Plain, Alberta, Canada Registered: 01-20-2001 |
quote: OK, I hope I can clarify. Clear as mud?
quote: No, that's something different. The & symbol means "the address of" (i.e. a pointer to that variable) when calling a function, or "a reference to" in a function prototype. Two different things that confuse a lot of people (and I can clarify if you want), but it's basically unrelated to the .h/.cpp question. Just FYI, here is an .h and .cpp with functions that use the & symbol: blah.h
blah.cpp
------------------ Check out this webhost! Fantastic prices, features and support! [This message has been edited by BrianT (edited October 17, 2007).] |
|||
arissa_nightblade![]() Member Posts: 70 From: Registered: 02-10-2007 |
Ok I think I get it.. So any function you use, you have to write them out twice? Write out the function first in the .h file then write it again in the CPP file but include the body of the function also? ------------------ |
|||
Briant![]() Member Posts: 742 From: Stony Plain, Alberta, Canada Registered: 01-20-2001 |
quote: You got it. Note the only reason for putting it in the .h file is so that multiple .cpp files can know about it. If you only use a function in one .cpp file, you don't have to put it in a .h file (but then you either have A. put its body *above* where it's called from, or B. put its declaration *above* where it's called from and its body *below* where it's called from. Basically, the whole thing boils down to this: the compiler is stupid and you have to let it know what parameters a function receives *above* where you call that function. The compiler looks at files top-to-bottom, not all-at-once. If it comes to a call to a function it doesn't know about yet, you get a compile error. ------------------ Check out this webhost! Fantastic prices, features and support! [This message has been edited by BrianT (edited October 17, 2007).] |
|||
dartsman![]() Member Posts: 484 From: Queensland, Australia Registered: 03-16-2006 |
quote: Hope you (or others) don't take offense to this... but... Potential job as a programmer... I do hope you have a good year or two before this test. ------------------ |
|||
arissa_nightblade![]() Member Posts: 70 From: Registered: 02-10-2007 |
quote: I've never had an actual job as a programmer. The only programming I've really done over the years was hobby/in my spare time and the classes from college, but they only taught the very basics of C++ which I already knew most of it from high school. I am sure the job will be asking advanced questions and I will have to do stuff I've never done before, so that's why I want to brush up on this stuff and make sure I at least have the concepts done. I've been exploring other languages besides C++. ------------------ |
|||
arissa_nightblade![]() Member Posts: 70 From: Registered: 02-10-2007 |
Random question... I've looked around gamedev.net and noticed a lot of C++ programs use either Directx or SDL in addition to C++.... are those the libraries you need in order to display graphics on the screen? Which one is better? ------------------ |
|||
dartsman![]() Member Posts: 484 From: Queensland, Australia Registered: 03-16-2006 |
quote: O_o which company are you applying for??? lol ------------------ |
|||
arissa_nightblade![]() Member Posts: 70 From: Registered: 02-10-2007 |
quote: A company called Big Huge Games. ------------------ |
|||
MastaLlama![]() Member Posts: 671 From: Houston, TX USA Registered: 08-10-2005 |
Is that the same Big Huge Games that put out the Rise of Nations series? | |||
arissa_nightblade![]() Member Posts: 70 From: Registered: 02-10-2007 |
Yes ![]() So now you know why I'm stressing over this test x_x ------------------ |
|||
SSquared![]() Member Posts: 654 From: Pacific Northwest Registered: 03-22-2005 |
That's cool. Do you need C or C++ help? Most of your questions and the answers have been in regards to C. You may want to look here: http://www.parashift.com/c++-faq-lite/ For some reason, the site has been down. Try doing a search for "C++ FAQ Lite". It's a nice look at various questions and how-to's in C++. And looking at GameDev was a smart idea too. DirectX and SDL are just two of the MANY possibilities out there. DirectX is fairly low level while SDL is on top of DirectX/OpenGL. The best advice is to find out what engine the company actually uses. Is it something comercially available or built in house? If publically available, then do research on the product and understand its components. If they use something in-house, then dig a little deeper and find out if there is ANYTHING available online regarding their engine. I have a set of various C++/OO questions I ask during interviews based on skill level and understanding. Here are a few: 1) What is the difference between a class and an instance? |
|||
arissa_nightblade![]() Member Posts: 70 From: Registered: 02-10-2007 |
Thank you for the help! ![]() ![]() Thanks for the explanation on the SDL/Directx thing. That question was just for my own curiosity. I don't know if the company uses that or not, but I will inquire about it more if/when I manage to pass this test. I think for now, however, it's just straight c++ coding without the use of anything too complex like including graphics -- though I could be wrong >.> Thanks again for your help and advice! ^_^ I will study those questions and continue my research. This has helped me a lot and a lot of things are starting to come back to me again. [This message has been edited by arissa_nightblade (edited October 18, 2007).] |
|||
MastaLlama![]() Member Posts: 671 From: Houston, TX USA Registered: 08-10-2005 |
Big Huge Games uses an in-house engine called Big Huge Engine |