We define a C++ class in a .h
and define its methods in a .cpp
, but it makes the code look less organized.
I want to put all method's definition in the class definition which is in a .h
file, but I'm worrying that the compiler generate duplicated code for the same methods/functions when one class header file is included by different files.
Does the linker find out and merge the duplicated code pieces to reduce the file size?
If not, is it better to use .hpp
instead? I heard that a .hpp
is for this.
And it does make minor difference when I just change a .h
file for a .hpp
(I don't know why), compiled with G++.