Last updated:2026-10-12
C++ Header-Only vs Implementation Separation¶
I have recently seen some friends ask a few rather interesting questions, so here is a round-up. These are questions that have come up in real interviews — see how many you know and test your fundamentals.
Interview question 1: What style do you usually write code in? Header-only? Or declaration separated from implementation?
Interview question 2: In C++, can every function have its implementation separated from its declaration? Why?
Interview question 3: What methods exist for separating a template's declaration from its implementation? Please illustrate the pros and cons of each with examples, along with their applicable scenarios?
Related Topics¶
- C++ Avoiding the Default Constructor | C++那些事
- C++ Class Initializer List Idiom | C++那些事
- C++ Prefer Class Templates over Function Templates | C++那些事
- C++ copy-and-swap Idiom | C++那些事
- C++ Dependency Injection | C++那些事
- C++ enum class Strongly Typed Enums | C++那些事
- C++ Lazy Evaluation Idiom | C++那些事
- C++ Lookup Table Idiom | C++那些事
- C++ Member Pointers and Type Information | C++那些事
- C++ Mixin Idiom | C++那些事