Visual studio allow you to create "inlined" classes (if I am not mistaken with the name). So class header and implementation all in one file.
H. file contain definitions and declarations of the class and functions, there is no .cpp file at all.
So I was wondering if there is any penalty for doing it that way? any disadvantages ?
Thanks a lot
any penalty for doing it that way? any disadvantages?
Yes. If you need to change the implementation of the class, since this is in a header file, all users of the class need to recompile, even though they should only be concerned with the interface. For some projects, this can be quite expensive.
You can put the complete implementation of a class in the header with any compiler. There's usually a penalty in terms of compile time -- the header will be compiled separately for each source file that includes it.
There may be a penalty in terms of code bloat as well -- putting the function definitions inside the class definition implicitly declares them inline, so there may be an increased likelihood of the compiler generating code for each of them individually instead of generating code in one place, and generating calls to it elsewhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With