Header files

Programming Reality Factory and Genesis3D.
Post Reply
User avatar
jonas
Posts: 779
Joined: Tue Jul 05, 2005 5:43 pm
Location: Texas, USA
Contact:

Header files

Post by jonas »

Does anyone know were you can find documentation that tells the functions header files have and how to use them?

I've been Fiddling around with c++ and making several small useless programs, but need more help.
Last edited by jonas on Tue Nov 08, 2005 9:15 pm, edited 4 times in total.
Jonas

Focused, hard work is the real key to success. Keep your eyes on the goal, and just keep taking the next step towards completing it. If you aren't sure which way to do something, do it both ways and see which works better. - John Carmack
User avatar
Handless
Posts: 21
Joined: Wed Nov 02, 2005 12:52 am
Contact:

Post by Handless »

I don't know if you still need help w/ this or not.. But if you do:

It's pretty simple. Headers contain your function declarations, type definitions, and pre-processor directives. ie: You should declare all classes, variables, etc. in headers.. You should avoid using function definitions in headers to. If you need examples I can post.

I'm sure if you google it, you'll find plenty of resources and tuts.
User avatar
jonas
Posts: 779
Joined: Tue Jul 05, 2005 5:43 pm
Location: Texas, USA
Contact:

Post by jonas »

Yes I would like any help I can get. Thanks for taking the time to even look at my post. I google it but I either skipped over the one's I needed or didn't go through enough pages to get to it.

It would help a lot if you could help me take a header file and decode it. Too see what functions it has.


Thanx in advance.
Jonas

Focused, hard work is the real key to success. Keep your eyes on the goal, and just keep taking the next step towards completing it. If you aren't sure which way to do something, do it both ways and see which works better. - John Carmack
User avatar
Handless
Posts: 21
Joined: Wed Nov 02, 2005 12:52 am
Contact:

Post by Handless »

np,

If you have a header file already just post it and I will tell you what it does and how to use it. I looked for a good tut on google, and sadly they are all lacking good explanation.. I'll post some examples.

If you just need to use headers to declare functions and avoid classes it's extremely easy to do so:

simple.h

Code: Select all

// Add preprocessor commands so this will only be defined once
#ifndef simple_h
#define simple_h

bool function();

#endif
main.cpp

Code: Select all

#include "simple.h"

// Main Loop
int main()
{
     bool result = function();

     return 0;
}

// Function Definition
bool function()
{
     return true;
}
If you want to use classes, I always make a header file first and declare all classes and functions:

CSimple.h

Code: Select all

// Add preprocessor commands so this will only be defined once
#ifndef CSimple_h
#define CSimple_h

class CSimple
{
public:
   function();
   // Any public declarations go here
private:
   // Any private declarations go here
protected:
   // Any protected declarations go here
};

#endif
Then I make a source file to host all definitions. ie: the logic of the program:

CSimple.cpp

Code: Select all

#include "CSimple.h"

bool function()
{		
     return true;
}
Then I link to it in the main loop somewhere:

main.cpp

Code: Select all

#include "CSimple.h"

int main()
{		
     // Get Class and Function
     CSimple simple;

     bool result = simple.function();

     return 0;
}
Hope this helps..
User avatar
jonas
Posts: 779
Joined: Tue Jul 05, 2005 5:43 pm
Location: Texas, USA
Contact:

Post by jonas »

I don't have a specific one. I would like to learn the functions held with in a dev-cpp header, that is for creating sockets and connecting to IP address's. If I can learn about that I would like to help with RF multiplayer. I will have to post the file from my other computer onless you have one. And that is if you even want to take the time to explain it!
Jonas

Focused, hard work is the real key to success. Keep your eyes on the goal, and just keep taking the next step towards completing it. If you aren't sure which way to do something, do it both ways and see which works better. - John Carmack
User avatar
AndyCR
Posts: 1449
Joined: Wed Jul 06, 2005 5:08 pm
Location: Colorado, USA
Contact:

Post by AndyCR »

this might help, i dont know what skill level you are with c++, but this is a complete book on it free. http://www.mindview.net/Books/TICPP/Thi ... CPP2e.html
User avatar
jonas
Posts: 779
Joined: Tue Jul 05, 2005 5:43 pm
Location: Texas, USA
Contact:

Post by jonas »

I've allready got that one but thanks I'm sure that one will come in handy for a lot of other people. I like how it explains everything as objects. Makes it easier to think thru your program. I haven't finished all of it, yet because its so long.
Jonas

Focused, hard work is the real key to success. Keep your eyes on the goal, and just keep taking the next step towards completing it. If you aren't sure which way to do something, do it both ways and see which works better. - John Carmack
Post Reply