[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Header Files

Posted on 1998-08-21
4
Medium Priority
?
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.
Suggested Courses

656 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