How do you make your own header files? Help please!

Nov 4, 2012 at 11:11pm

I'm not talking about just a text file with code, I mean
a header file containing functions C++ or any other header library has.
:) Hope you can help. Thanks.
-legit





Nov 4, 2012 at 11:20pm
A header file is just a text file with code. If you want to put function in it, just put functions in it.

http://www.cplusplus.com/forum/articles/10627/
Nov 4, 2012 at 11:25pm
I think the question may be not really about the header file, rather it is about the library file which contains the compiled code of the functions.
Nov 4, 2012 at 11:36pm
I see. In which case, that's also easily answered. Write the functions, compile them (whilst telling your compiler that you want a library rather than an executable) and bingo - you've got a library. Link to it as usual.
Nov 4, 2012 at 11:51pm
I don't think you get where I'm coming from. I want to create my own functions.
Nov 4, 2012 at 11:59pm
And he told you how to do so. Create a header file, write your functions and then include the header wherever you need to call said functions.
1
2
3
4
5
6
7
8
9
10
11
12
//Header.h
int Func(int param)
{
return param;
}

//main.cpp
#include "Header.h"
int main()
{
return Func(0);
}


EDIT: Although a header should only contain function declarations. You should stick the definitions in a separate cpp file.
Last edited on Nov 5, 2012 at 12:00am
Nov 5, 2012 at 12:24am
I want to create my own functions.


Did you read this?
http://www.cplusplus.com/doc/tutorial/functions/
Nov 5, 2012 at 12:36am
You're going to need brick and mortar.

And love. Lots of love.

Love and cookies.
Topic archived. No new replies allowed.