Thread: header file

  1. #1
    Registered User FCF's Avatar
    Join Date
    Dec 2001
    Posts
    40

    header file

    Actually this Q was discussed b4...sorry to ask it again.

    In coding a Linked-list program, it is better to code the linked-list's header file first(I did it by refering the note distributed from my lecture). Eg:
    Code:
    /* begin ListInterface.h */
    ...
    typedef struct nodeTag{
    int data;
    struct nodeTag *next;
    }NODE_TYPE;
    ...
    /* not details caz just example */
    /* end ListInterface.h */
    Then, i code the ListImplementation.cpp file which contains all the functions related to the operation in linked-list like insert, delete, search... and first Q1 comes: Why i have to includes the #include "ListInterface.h" in this ListImplementation.cpp?
    Furthermore, when i procede, and code the main program, i must #include "ListInterface.h" also. Then, i code the rest until finish and compile. The result was: ERROR: Function need to be resolved.(the function in ListImplementation.cpp). I don't understand this, but i replaced the #include "ListInterface.h" with the #include "ListImplementation.cpp" and it works!!! No more errors and the program run. Why?

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    52
    Looks to me like you have the function in the .c file, not in the .h

    If you want it in the .h file, try using 'extern' before the functions

    I don't really understand what you are trying to say, but from what I gather this looks like the problem. If it compiles without including the .h file, it isn't needed, so try taking a look at the .cpp file and then transferring certain things over to the .h or make it all in the .c

    Which I suppose takes me to the first question, you only need to #include a file if you want to use structures, void's, int's, etc, in more than one .c file. Also it makes it look neater if you use header files, because some things just look like they belong there, not in .c files, even though they may work But the answer is you don't _HAVE_ to #include anything.

    Hope this answers something, heh
    - Daniel Wallace

  3. #3
    Registered User FCF's Avatar
    Join Date
    Dec 2001
    Posts
    40
    Looks to me like you have the function in the .c file, not in the .h
    Thank u for trying to help.
    I code the functions related to linked-list operations in the ListImplementation.cpp. And, when #include "ListInterface.h" in main, it can't be compiled. Actually wat is the meaning of function need to be resolved? After all, i will try to add the extern key word in the functions in the ListImplementation.cpp.

  4. #4
    ~- Y u n a -~ beely's Avatar
    Join Date
    Dec 2001
    Posts
    291
    hey FCF, did you copy your header file on the debug folder??
    if no, then that's a problem that can exe your header file.

  5. #5
    Registered User FCF's Avatar
    Join Date
    Dec 2001
    Posts
    40
    Wat do u mean???

  6. #6
    ~- Y u n a -~ beely's Avatar
    Join Date
    Dec 2001
    Posts
    291
    ermm, when you build your source code, it'll store on the "DEBUG" folder. right ? then, i guess you should have to try to copy the header file on the debug folder la ..

  7. #7
    Registered User FCF's Avatar
    Join Date
    Dec 2001
    Posts
    40
    i will try. Thank u your help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Replies: 30
    Last Post: 06-19-2006, 12:35 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM