Thread: How do use home made header files

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    16

    Question How do use home made header files

    Ok lets say i made a header file header.h and i want to use it in my program i know i would use
    #include "header.h"
    but that means im going to have to give it out with my program right. and if so is there any other way i could manage to use it in my program with out handing it out with the program.
    • 0927
    • a.k.a 0 9 two 7

  2. #2
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    The header (*.h) file only contains class and method declarations. The definitions go in a (*.cpp) file. So who cares who sees the header file, infact it is the interface. You want other programmers to see the header.

  3. #3
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    exactly... well put.


    **************************************************
    //file.h

    #ifndef C_
    #define C_

    class c
    {

    public:

    // This function outuputs the word test people can read this
    // so that they know how to implement this class

    void test();

    };

    #endif

    **************************************************
    #include <iostream>
    using namespace std;

    //file.cpp
    // this file is compiled with the header into object code and the object file is given to the class user

    void c::test()
    {

    cout << "Test" << endl;

    }

    ************************************************** *

    Compile the two files (but not link) makes

    file.obj

    Give file.obj and file.h to class user... then your implementation is not visible, but how to use your class is visible because of your descriptions.

    (may be mistakes... turns out I am in a real hurry and am typing thru this really fastt)
    Blue

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    194

    Re: How do use home made header files

    Originally posted by 0927
    Ok lets say i made a header file header.h and i want to use it in my program i know i would use
    #include "header.h"
    but that means im going to have to give it out with my program right. and if so is there any other way i could manage to use it in my program with out handing it out with the program.
    If you want to pass out a binary exe file that is already compiled then you do NOT need to distribute the .h file.
    If you want to give out source code then you will have to give out the .h file.

  5. #5
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    The .h file is insignificant in terms of giving away your code because your definitions are in .cpp files, at least if you did it right.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Header files in .h
    By swgh in forum C++ Programming
    Replies: 5
    Last Post: 05-29-2008, 08:58 AM
  2. Help using Header Files
    By d34n in forum C Programming
    Replies: 8
    Last Post: 04-21-2008, 11:06 PM
  3. need help with menu program and header files
    By DFC in forum C++ Programming
    Replies: 12
    Last Post: 12-07-2005, 12:09 PM
  4. Missing header files and libraries with Borland
    By quagsire in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2003, 06:19 AM
  5. Header files
    By Jez_Master in forum C++ Programming
    Replies: 2
    Last Post: 04-08-2002, 07:56 AM