Solved

Header Files

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

809 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