Archived

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

cpp files

This topic is 5651 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 have seen many programs that have functions in one .cpp file and use them in another .cpp file, i guess its for organization, when i try to do this myself, i get an error in my program saying that the function cannot be found, can anyone tell me how to fix this? ,Matt -= kill one your a murderer, kill thousands your a conquerer =-

Share this post


Link to post
Share on other sites
If you have a function:

file1.cpp:
int bleh()
{
return 1;
}

Then you can do:
file2.cpp:
int bleh();

void omgwtf()
{
printf( "%i", bleh() );
}

But, doing like that makes it more work when you access bleh() from multiple files. So:

file1.h:
int bleh();

file2.cpp
#include "file1.h"

void omgwtf()
{
printf( "%i", bleh() );
}

Share this post


Link to post
Share on other sites
Make sure you''re including your ''custom'' header file in your project. Also remember that when including your own libraries, you need to use quotes not the angled brackets (less than/greater than).

i.e. #include "foo.h"

The other thing to make sure of is that you''ve got the function name spelled correctly (this has been the root of many a late night debugging session because it''s so easy to overlook sometimes).


SysOp_1101

Share this post


Link to post
Share on other sites
There''s an excellent article on file organization somewhere on this site (which I can''t seem to find now, of course). You should check it out.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/

Share this post


Link to post
Share on other sites