Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Question. Header files.

Author
Message
Murloc
15
Years of Service
User Offline
Joined: 28th Dec 2008
Location: Utena,Lithuania
Posted: 1st Jan 2009 16:06
Okay,I am not so noob at C++ but still,know more advanced commands more than the basics. This is sad. And now I need to know:

For what I have to make .h files? Do this declares voids bools ints and other stuff? Can I make this without header files? What is #pragma once for? I am asking here because at tutorial site it's not written about for what the header files is.


Sorry for my english,I am kinda drunk now.

Theory-When you know everything,but nothing works.
Practice-When everything works,but you don't know why.
Programming merges these two-Nothing works,and you don't know why.
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 1st Jan 2009 16:31 Edited at: 1st Jan 2009 16:31
Header files typically include things like class and functions declarations. Then you typically have a CPP file for each header file that implements these functions. So the header may look like this:



And the CPP file may look like this:



However typically the header file will have some sort of include guard. This ensures that the header will never be included more than once, as that could cause multiple declarations of the same class/function. #pragma once is one of these guards; it ensures that the header will only be included once. So here would be the header with the include guard:



As for the voids, ints, bools thing, void is a return type. It is only really used in functions to show that no value is returned from that function. It can also be used to declare void pointers but that's another topic. Ints and bools are data-types which can be used for variables and returned from functions. If you have a function which adds two numbers together and returns the answer, you may want it to return an int.



That function will take two integer parameters and return their sum. Bools are basically a flag which is either true or false. If you want to make a function that checks if two numbers are the same it would return a bool; true if the two numbers are the same, or false if they aren't.



And to answer your question, no, data-types and return-types are not used only in header files, they can be used anywhere.

Hopefully that answered your questions, I'm kind of tired so I might have missed some stuff. If you have any questions feel free to ask.


Murloc
15
Years of Service
User Offline
Joined: 28th Dec 2008
Location: Utena,Lithuania
Posted: 1st Jan 2009 18:35
So how I understand header files are files to store void structures,classes and so on?

Feeling kinda stupid now,but how I can convert what void returns to char to draw it using dbText(int x,int y,char *szText)?

Theory-When you know everything,but nothing works.
Practice-When everything works,but you don't know why.
Programming merges these two-Nothing works,and you don't know why.
Indecom
17
Years of Service
User Offline
Joined: 23rd May 2007
Location:
Posted: 1st Jan 2009 22:17
dbStr( value );
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 1st Jan 2009 22:35
Quote: "Feeling kinda stupid now,but how I can convert what void returns to char to draw it using dbText(int x,int y,char *szText)?"


I don't think you understood me right. If a function returns a void it means it doesn't return anything, therefore there isn't any value to convert to a char pointer. If the function returns an int, float, etc. then as Indecom says you can use dbStr( ) to convert to a char pointer.


Murloc
15
Years of Service
User Offline
Joined: 28th Dec 2008
Location: Utena,Lithuania
Posted: 2nd Jan 2009 01:41
Thanks!

Theory-When you know everything,but nothing works.
Practice-When everything works,but you don't know why.
Programming merges these two-Nothing works,and you don't know why.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 2nd Jan 2009 03:47
Or if the function returns a void pointer.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office

Login to post a reply

Server time is: 2024-09-30 13:15:33
Your offset time is: 2024-09-30 13:15:33