Solved

Header Files

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

867 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

22 Experts available now in Live!

Get 1:1 Help Now