Skip to main content
GameDev.net gamedev.net
🔒 Locked

c++ help

Started by ury2ok Dec 8, 2001 at 11:56 AM 3 replies 300+ views
Original Post
ury2ok
ury2ok
I know VB pretty well but am a beginner to c. i learnt the console version and not the windows version. My first question is based on the following statement. And there’s also a couple of header (.H) files: Utils.h contains a ‘description’, called a prototype or declaration, for each of the functions implemented in Utils.cpp. As long as any other source file has access to this header file, it can use the functions contained inside. so that means if i make a function in a .cpp file (lets say game.cpp) and i have another .cpp called functions.cpp i couldnt make a call from game.cpp and access the function that is in functions.cpp? So if i wanted to access this function i would have to stick it into a .h file and #include the file at the top of game.cpp? Thanks
coelurus
coelurus
Normally, you can include the cpp file directly. I stick to h files though, because I haven''t learnt what''s good or bad with them, most use h files
Fruny
Fruny
You cannot use a function prior to its _declaration_ "int foo();", not necessarily its _definition_ "int foo() { do stuff; }".
You must thus have declarations of functions with extern linkage in each source file. You could add them to each cpp file, but the easiest way is to stick them in a header file. Just like it is done with C library functions.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
BASSOFeeSH
BASSOFeeSH
Yes, and remember to use quotes instead of angle brackets when you #include your own header files.

^^^^^^^^^^^^^^^^^^^^^^^^^
Wait, wait, wait....who''s Nambla Fett?
-- What would Sweetness do?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.