Solved

Header Files

Posted on 1998-08-21
4
209 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 20 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now