Advertisement

header file standard?

Started by February 27, 2002 09:12 AM
1 comment, last by evilclown 22 years, 8 months ago
Do people usually declare functions in .h files, and put code in cc files? Like this example: main.cc
  
#include "header.h"

int main() {
  // code ..

  return 0;
}
  
header.h
  
int somefunc();
  
header.cc
  
int somefunc() {
  return 0;
}
  
I''ve always made the file with main() in it be called something.cc or cpp. Then I include headers that prototype functions, and have the functions in it. Is there a reason why you would want to do the example above?
Yes, this is common. It allows you to use the same function in several cpp files without the linker complaining about multiple function definitions.

--
Cats cannot taste sweets.
Advertisement
Yes. It''s far better to do it this way, for the reasons above.

It''s also all about keeping interface and implementation seperate. If you use a function, you need not know how it works internally, as long as it does what it''s responsible for.

It also increases readability and compile time of code, especially when the files get large.

- Pete

This topic is closed to new replies.

Advertisement