Page 1 of 1

Header files

Posted: Sat Oct 15, 2005 1:19 am
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.

Posted: Wed Nov 02, 2005 1:59 am
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.

Posted: Wed Nov 02, 2005 3:03 am
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.

Posted: Wed Nov 02, 2005 5:02 pm
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..

Posted: Thu Nov 03, 2005 3:49 am
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!

Posted: Thu Nov 03, 2005 3:53 am
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

Posted: Thu Nov 03, 2005 4:03 am
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.