Archived

This topic is now archived and is closed to further replies.

c++ help

This topic is 5848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
don''t include .cpp files, that duplicates the code of the function. By including headers instead the same function is used everywhere. It gets even worse if you are including variables in a cpp, then you have two copies of the varaible, they are not the same variable. That will ruin your program.

Share this post


Link to post
Share on other sites