header files

This is a discussion on header files within the C++ Programming forums, part of the General Programming Boards category; What is the point of making a header file yourself and what do you put in them? I checked the ...

  1. #1
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052

    header files

    What is the point of making a header file yourself and what do you put in them? I checked the book that I am learning from (as always) and it doesn't say anything 'bout it.

    Thanks
    -Chris

  2. #2
    Unregistered
    Guest
    You put functions in them and stuff. like this:

    Example.h:
    Code:
    #include <iostream.h>
    int function(){
    cout << "hi" << endl;
    return (0);
    }
    And in main.cpp:
    Code:
    #include "Example.h"
    int main(){
    function();
    return (0);
    }
    it would print:
    'hi'

  3. #3
    Xterria
    Guest
    o ya that was me helpin u all me see

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    79
    Actually, you don't even need to do that much.

    //function.hh
    void func();

    //function.cc
    #include <iostream>

    using std::endl;
    using std::cout;

    void func()
    {
    cout<<"hi"<<endl;
    }

    //main.cc
    #include function.hh
    int main()
    {
    func();
    }

    would output "hi"
    All generalizations are false

  5. #5
    Ethereal Raccoon Procyon's Avatar
    Join Date
    Aug 2001
    Posts
    189
    There are two reasons why you may want your own header files.

    1) You're writing a huge program and want to break it up into manageable pieces.

    2) You use the same user-defined functions/classes in a lot of different programs and don't want to have to copy and paste the code every time.

    Usually the .h file contains only class definitions and function prototypes (the rest goes in a separate .c* file without a main() function) , but it can contain implementations as well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 11:21 AM
  3. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 06:12 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21