3 ms·
I'm not a C++11 developer, I've done a little C++ in the past. What is the pride in putting all the code in the header file? Shouldn't the declarations be there
by ricket 12y ago
I'm not a C++11 developer, I've done a little C++ in the past. What is the pride in putting all the code in the header file? Shouldn't the declarations be there, and the definitions be pulled out into a .cpp file? Is it somehow smaller, faster, more convenient to have it all in a header file?
- jgh 12y agoHeader libraries are easier to add to your project because there are no build scripts to figure out or cross-compiling to do or whatever. A lot of Boost is header-only, for example. GLM (OpenGL Mathematics), too, is header-only. OTOH if you end up modifying a header that's included in a whole bunch of places, woe unto you.
- TheDong 12y agoThe reason Boost is headers only is you have to be a header to be generic. Implementations outside of headers have to friend / otherwise be not truly generic.
- jgh 12y agoYes, good point. You're right about that.
- deleted 12y ago[deleted]
- theyoungestgun 12y agoAssuming you mean friend in the standard cpp way, that's not exactly correct. http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file http://stackoverflow.com/questions/495021/why-can-templates-...
- deleted 12y ago[deleted]
- pjc50 12y agoIt's unavoidable if you use templates in the interface. It tends to make builds disastrously slow though.