Jump to content
  • Advertisement

Archived

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

azaxaca

how to create header file

This topic is 5985 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 want to create a header file so i can put aside all the messy stuff in it and leave the WinMain and Scene stuff in the cpp file i tried just saving the document as .h file but borland 5.5 dont seem to recognize it...... I thought i had to compile a cpp file into a .h file.... i dont know how to do that wit borland

Share this post


Link to post
Share on other sites
Advertisement
ummmmmm WHHHAAAAATTTT?

I think you are a bit confused about what header files are. Typically a header doesn''t even have any source. Just declerations for classes and functions. You then do the definitions of these in a .cpp (or .c) file (usually with the same file name) Then wherever you want to use those classes or functions you include the header file at the top.

Hope that helps

Share this post


Link to post
Share on other sites
oh...............

sorry i ma newbie

so i cant put the stuff aside?????

o wait, but i could have multiple cpp that could be compiled into one exe file right??

Share this post


Link to post
Share on other sites
you can put that stuff inside aslong as you only include it once.
It won''t let you pre-compile it either (makes compiling time faster)

lets say you had a program

  
// test.c

#include <stdio.h>

void soandso(char *s)
{
printf("so and so is a %s\n",s);
}
void main(void)
{
soandso("wanker");
}




you can make it into two files

  
// test.h

#include <stdio.h>
void soandso(char *s)
{
printf("so and so is a %s\n",s);
}

// test.c

#include "test.h"

void main(void)
{
soandso("wanker");
}



You should be using two seperate C files though, and not placing the code in the header. The header ususally holds the information for calling the function, but not the code it self. Helpful when linking multiple C files together. You''ll leran that as you go along.



Beer - the love catalyst
good ol'' homepage

Share this post


Link to post
Share on other sites
..........how do i do that

getting multiple cpp files to compile together

i cant even make a header file properly

i saved all function declaration and include stuff into a text
and then saved it as base.h (i didnt put any code in it)

when i try including with it, borland compiler says "declaration styntax error"
(i typed #include "base.h")

Man im lost...

Share this post


Link to post
Share on other sites
RTFM!! That acronym is way to funny . I''m just joking; we were all once newbies.

I would suggest getting a book on C++; go to Amazon.com or something. I''ve heard Sam''s teach yourself C++ in 24 days is good; though I''ve never tried it. I have Deitel & Deitel''s C++ How to Program and a few others; I thought it was good. Or, you can find one of the many C++ tutorials on the Internet.

Good Luck!

Share this post


Link to post
Share on other sites
well i found tones of cpp tuts on the internet
and im very familiar wit the language(although i ddint master it) i even have a boook(a crappy one at that) but none has ever taught me how to compile multiple files...

ps. i cant afford to buy another book....

Share this post


Link to post
Share on other sites
Well, I assume you are on Windows so you don''t need makefiles or such things. Just add the files you want to compile to your project (I don''t use Borland, but MSVC should be similar). And #include the headers of the *.cpp files into the *.cpp files you want them to be included in. You''ll have to look up Borland''s documentation since I don''t know if Borland uses projects or not;it should be similar.

For example:
You included test.cpp test.h and main.cpp in your project, so if you want to use some functions in test.cpp in main.cpp just do this:
  
// In main.cpp

#include "test.h" // Gives you access to the functions in test.cpp assuming you put your function prototypes or class defintion in there.

Share this post


Link to post
Share on other sites
In VC++ the .cpp files have to be included in the project for them to compile. If they are just extra functions and stuff, ie without corresponding .h files, then just compile the project containing all the .cpp files. Hopefully this is similar to the Borland approach

A common mistake is to try including a .cpp file which cannot be done

Share this post


Link to post
Share on other sites
regarding the multiple C++ file linking thing.

Which Borland 5 is it?

Borland C++ Builder 5.x?
Borland C++ 5.x?
Borland C++ 5.x free download?


If it is the free download, you can use the makefile or link manually.

If it is builder5, it is under the menu or pretty much anything with the mouse, or you type useinit.

if it is c++5 then you would do as Floppy (nice name ) said and it is under the menus at the top.


Tell us which one you use, and if I see this topic again, I will try and post a small example for you if no one else does.


The code in each file is actually quite simple, it is just the linking part that is probably confusing the hell out of you at the moment. My guess is that you have to type it out (free console version) which is a real pain in the rump.



Beer - the love catalyst
good ol'' homepage

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!