Hacker News new | past | comments | ask | show | jobs | submit login

Even on C++, regardless of templates, most code doesn't need to be header only, other than laziness to properly learn how to work with compilers and build systems.



Hello. Forgive my ignorance and possible misunderstanding of your 'most code' qualifier.

If I have a template header .hpp and I do not wish to specialize the template function bodies in a .cpp file, the template header function bodies must be declared in the .hpp, right?


Yes and no.

Yes it needs to be on the header, however depending on what is the goal, many operations could eventually be delegated to helper functions or PIMPL classes, which aren't fully exposed on the header.

And for the lucky users of VC++ 2022, there is also the option to use modules instead, where templates are then exposed via the module metada.


Helper functions, PIMPL, that's all fine - the declaration and function body of the template is still defined in the .hpp. Whether all of the body of the template is also defined there was not my concern in asking.

Thanks for your comment.

I will have to dig in to modules in due course.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: