Thread: *.h file, function definitions.. help

  1. #1
    Registered User
    Join Date
    Dec 2004

    Question *.h file, function definitions.. help

    I was told by my professor that my function prototypes should be included in my *.h file. But, do I also include the function definitions in that file, or do those go in my *.cpp file? Please help..

    Josh Stevanus

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Function definitions go in the .cpp.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Northern Virginia/Washington DC Metropolitan Area
    An example of how you potentially could have things set up in a sample project...

    #ifndef FUNC_H
    #define FUNC_H
    int func(int);
    #include "File.H"
    int func(int data)
    #include "File.H"
    int main()
        int result, val;
        result = func(val);
    Thus this sample project has 2 cpp files and 1 header file. You compile the 2 cpp files into object files and its the linkers job to combine those (typically along with some other library code) into a fully functioning executable file.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM