Re: Proper use of Header files
Re: Proper use of Header files
- Subject: Re: Proper use of Header files
- From: Howard Moon <email@hidden>
- Date: Mon, 29 Oct 2012 08:39:44 -0700
On Oct 28, 2012, at 11:49 AM, David Rowland wrote:
> If the header is read by more than one implementation file, the compiler will generate more than one copy of the code, probably causing problems with the linker.
There is no such problem. Try it and see. If you're getting multiply-defined symbols, then you've forgotten include guards (or #pragma once).
The main reason for not putting all your code in headers is to keep compile times down, (when using incremental builds). If you change any code in the header, then all files in which that header is included must be recompiled. For small enough projects, or if not using incremental builds, that's really irrelevant.
Another reason is readability, because it's a lot easier to visually scan a header for function names (and associated comments) then it is to attempt that with a complete implementation file with all its code defined, especially in larger classes. (I think it makes doxygen output easier to work with, too.)
It also allows you to have "circular" dependencies, because you can forward-declare a co-dependent class in the header, and only include its header in the implementation file. Otherwise, your implementation code in each class would be attempting to include the implementation code of the other class, which would int turn attempt to include the first class' implementation code, etc..
As you mentioned, templates require that the implementation details be there in the header. So it can't be illegal or improper to do.
Personally, I do it the way my company management tells me to do it, unless I can convince them that I have a better way. :-)
-Howard
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden