Will03uk
Will03uk

Reputation: 3444

Should I use header-only classes or lib files?

I am creating an external library for general use. What Im asking is should I put every class in just .hpp files like boost does or should I compile it into a lib file and keep the two file per class rule. As far as I can see .hpp is used for speed, so you don't have to add a .lib for every class or a massive one for the whole thing and for cross-platform.

[edit] Whats your personal preference and why. My library would just be for my personal use. [edit] For statically linking the library

Upvotes: 2

Views: 333

Answers (2)

Puppy
Puppy

Reputation: 147028

This really depends on if you have cross-platform or templated code. You may not have an awful lot of choice about making the majority in header files if you need a lot of preprocessing to generate it. Otherwise, you should pre-compile as much as possible, as a general rule.

Upvotes: 1

jonaskje
jonaskje

Reputation: 121

For a class that is used in multiple compilation units (cpp-files) you will want to have as tiny header files as possible to keep down the build time. The bulk of your code should go into a cpp file.

Upvotes: 3

Related Questions