including header files.

Can someone give me the procedure for including user defined header files. Kind of has me stumped and can't find any decent tutorials on it.

Comments

  • : Can someone give me the procedure for including user defined header files. Kind of has me stumped and can't find any decent tutorials on it.
    :

    why do you need a tutorial to write just a single line of code?????
    [code]
    #include "myheader.h"
    ...
    [/code]
  • : : Can someone give me the procedure for including user defined header files. Kind of has me stumped and can't find any decent tutorials on it.
    : :
    :
    : why do you need a tutorial to write just a single line of code?????
    : [code]
    : #include "myheader.h"
    : ...
    : [/code]
    :

    Stober, I think you got him wrong. I belive that he's asking about splitting a program into various files using header files.
    I don't know any good tutorial about this on the net (try googling) but any worthful C/C++ book has to have a chapter about this.

    Homero C. de Almeida

    [italic]There's no dishonour in failure. For we aren't allowed to know wheter we'll achieve success or not. There is only one final shame, the cowardice of not trying.[/italic]

  • Yea, I mean how to split up the file into implemenation file and header file. I'm reading my c++ book now and theres not much on it. But I have messed around a little bit and learned #include is just like entering the entire contents of that entire file where ever you put it.

    This is what I did, which I do not think it's correct but it works below:

    main program: program2.cpp

    #include
    using namespace std;
    #include "LinkedList.cpp"
    int main(){//Code here


    implementation file: LinkedList.cpp

    #include "LinkedList.h"
    //Code here for Functions of LinkedList


    Specification file: LinkedList.h
    //Code here for the Class LinkedList.
  • [b][red]This message was edited by stober at 2006-2-19 9:41:59[/red][/b][hr]
    : Yea, I mean how to split up the file into implemenation file and header file. I'm reading my c++ book now and theres not much on it. But I have messed around a little bit and learned #include is just like entering the entire contents of that entire file where ever you put it.
    :
    : This is what I did, which I do not think it's correct but it works below:
    :
    : main program: program2.cpp
    :
    : #include
    : using namespace std;
    : #include "LinkedList.cpp"
    : int main(){//Code here
    :
    :
    : implementation file: LinkedList.cpp
    :
    : #include "LinkedList.h"
    : //Code here for Functions of LinkedList
    :
    :
    : Specification file: LinkedList.h
    : //Code here for the Class LinkedList.
    :

    [blue]Never include one *.cpp or *.c file in another -- include only *.h files. If you split the program into two or more source files then compile each sorce file separately and link the object files together along with libraries it uses. Modern-day compilers have projects that will do most of that work for you -- depends on the compiler you are using. If you are using command-line compiler and makefile then you need to make manual changes to the makefile.[/blue]

    [code]
    : main program: program2.cpp
    :
    #include
    using namespace std;
    #include "LinkedList.h"
    int main(){//Code here

    //
    //
    // LinkedList.cpp
    #include
    using namespace std;
    #include "LinkedList.h"
    // linked list code here
    /


    [/code]

    Program2.cpp and LinkedList.cpp are compiled separately, then the object files are linked together with other librarys. Notice that there is a LinkedList.h that is included in both *.cpp files -- it contains structure declarations and function prototypes, no code unless inline.



  • Well, I'm using Dev-C++ at the moment, The code I supplied works becuase it is just like putting the contents of the #include file into my code. I guess Dev-C++ is not compiling the LinkedList.cpp file first and linking object files. It is just compling program2.cpp. Eventually I will have to use a makefile on Unix but was using dev-c++ first.
  • : Well, I'm using Dev-C++ at the moment, The code I supplied works becuase it is just like putting the contents of the #include file into my code. I guess Dev-C++ is not compiling the LinkedList.cpp file first and linking object files. It is just compling program2.cpp. Eventually I will have to use a makefile on Unix but was using dev-c++ first.
    :


    use Dev-C++ menu Project-->Add To Project, and click on LinkedList.cpp.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories