?
Solved

Header Files

Posted on 1998-08-21
4
Medium Priority
?
222 Views
Last Modified: 2010-04-01
I am experienced in C and C++ but I am not veery experienced in making Header files and accesing
    them from a program,
    so I was hoping that someone could give me an example on how I could do something like that!

    Thanks

    Anton
0
Comment
Question by:smoothasice
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
dsch earned 40 total points
ID: 1170947
I am quite new to C++ but I think you are referring to the header files for your functions and varibles. So I hope this will answer your question.

eg of Header file.
/*Header example
file name: headername.h */
void SOMEFUNCTION(int, char);


class SOMECLASS
{
public:
    SOMECLASS();
    ~SOMECLASS();
private:
    int AVariable;
}

eg of file that contains the program.

#include "headername.h"

SOMECLASS::SOMECLASS()
{
   AVarable = 5;
}
~SOMECLASS::SOMECLASS()
{
}
void SOMEFUNCTION(int x, char S)
{
//your code goes here
}


I hope this is what you needed. If I am wrong or if I've made some monumental mistake anybody please let me know. I am trying to get experience in answering questions.
Bye for now, dsch
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170948
Did that answer your question?  If not can you explain what part of making header files you don't understand?  do you not know what should or should not go in?  Do you not know how to control things so the header code is not included multiple times?
0
 

Author Comment

by:smoothasice
ID: 1170949
nietod,
I do'nt realy understand how they link together, as in how I would make it so that main program can access the information in that header file.  That is mainly what I want to use the header file for.
if you can give me any clues as to how I could do this I would be very grateful

Anton
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170950
how can the "main program ... access the information in that header file"?  The main program file will include the header file, using the #include pre-processor directive.  You probably use this directive to include some of the standard C++ library files.  For example to include the string library you place

#include <string.h>

near the top of your program.  However, the < ... > version is really meant to be used for header files provided with the C++ compiler.  Header files you write should be included using

#include "filename.h"

where the < and > have been replaced with quotes.  The difference between the two is in where it looks for the files.  

Note all this directive does is that it tells the compiler to include the entire contents of the specified file at that location in the file being compiled.  

Does that answer your question?  or are we still missing the mark?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question