Thread: Declaring functions in a seperate file.

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912

    Declaring functions in a seperate file.

    If my main file has the line, "#include "myfuncs.h"", and it contains all the function prototypes, and I have all the actual code for the functions in myfuncs.h, would I stil have to have the function prototypes put in that file too? By prototypes I mean where you type void func_name(void) just above the main() function.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    No, as long as you include myfuncs.h before any of the functions are used.
    zen

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    It's generally not a good idea (though perfectly legal) to put actual code in .h files -- many compilers precompile headers, which makes compiling faster, but headers with initialized data or code in it can't be precompiled.

    It's also somewhat unconventional to put code in a header. But it is permitted.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    Originally posted by The V.
    It's generally not a good idea (though perfectly legal) to put actual code in .h files -- many compilers precompile headers, which makes compiling faster, but headers with initialized data or code in it can't be precompiled.

    It's also somewhat unconventional to put code in a header. But it is permitted.
    It may not be a good idea, but I had to in order to get a class template to compile in MSVC 6. Putting the definitions in a different file gave a bunch of linking errors.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Yup, MSVC 6 has some issues with templates.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf in different functions for the same file
    By bchan90 in forum C Programming
    Replies: 5
    Last Post: 12-03-2008, 09:31 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM