What are the benefits of a header only library and why would you write it that way oppose to putting the implementation into separate file?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are situations when a header-only library is the only option, for example when dealing with templates.
Having a header-only library also means you don’t have to worry about different platforms where the library might be used. When you separate the implementation, you usually do so to hide implementation details, and distribute the library as a combination of headers and libraries (
lib,dll‘s or.sofiles). These of course have to be compiled for all different operating systems/versions you offer support.You could also distribute the implementation files, but that would mean an extra step for the user – compiling your library before using it.
Of course, this applies on a case-by-case basis. For example, header-only libraries sometimes increase
code size &compilation times.