functions between cpp's
#1
I'm trying to use the drawequipicons() function that is in the renderhud.cpp in the dokill() function that is inside of the clientgame.cpp

I read that to use functions defined in another cpp, I need to prototype them in a header (.h) file and then #include it in my clientgame.cpp.

I'm not quite sure if drawequipicons() is prototyped in a header or not, how do I find that out?
Thanks given by:
#2
hmm.
I don't want to find it for you, look in protos.h.
Thanks given by:
#3
Well besides that, if it is prototyped, then I should be able to execute drawequipicons() without any errors right?

When I did this inside of clientgame.cpp, I got an error:

#include <renderhud.cpp>

It said in the Output that this line was skipped and then it gets an error on drawequipicons() since it was never defined.

EDIT: I CTRL+F in protos.h and typed 'drawequip' but it didn't find it in there. Does CTRL+F even work when you search for these things?
Thanks given by:
#4
In most text editors/IDEs, Ctrl + F will perform a search for text within the currently opened/focused file, not all files you may have a tab open for. This is why I suggested you get a program like AstroGrep in the other thread. It makes it easy for you to search the /src/ directory (all source code files) for certain text/line of code (rather than searching file by file manually with Ctrl + F).
Thanks given by:
#5
When I CTRL+F in VS, it has an option to search the entire solution/project. Isn't that the same though? I get the same search results with astrogrep.
Thanks given by:
#6
Not too sure about the VS option, sounds like it might/should work but I've never used it myself so I can't confirm. Maybe it only searches all currently open files in the project? (meaning you would have to open all source files for the project in the IDE then do it to get the same effect as an AstroGrep search)
Thanks given by:
#7
(01 Feb 13, 12:27AM)Lee Wrote: #include <renderhud.cpp>
?

(01 Feb 13, 12:27AM)Lee Wrote: EDIT: I CTRL+F in protos.h and typed 'drawequip' but it didn't find it in there. Does CTRL+F even work when you search for these things?
It becuse it is not defined there.
add "extern void drawequipicons(playerent *p);" in protos.h
or you can put it before use the function in clientgame.cpp.
Thanks given by:
#8
(31 Jan 13, 11:44PM)Lee Wrote: I'm trying to use the drawequipicons() function that is in the renderhud.cpp in the dokill() function that is inside of the clientgame.cpp

I read that to use functions defined in another cpp, I need to prototype them in a header (.h) file and then #include it in my clientgame.cpp.

I'm not quite sure if drawequipicons() is prototyped in a header or not, how do I find that out?

In the clientgame.cpp file on a line before doKill() add this:
void drawequipicons(playerent *p);

If you put it immediately before it will look like this:

void drawequipicons(playerent *p);

void dokill(playerent *pl, playerent *act, bool gib, int gun)

That bit of code is what is known as the prototype that you mentioned. In this case it lets the following code know that function is defined elsewhere.

@Jpablon: Functions in C++ have external linkage by default.
Thanks given by: