Anything which has internal linkage can be put in header file in C++ . Why? -
eg:- below examples. explanation in every case advantage.
1. static variable/object. 2. static const variable/object. 3. const variables. 4. inline functions .
static
@ namespace scope means "local translation unit", you'll new copy of object in every unit includes header.same thing.
these have internal linkage default.
these don't, language has rule says can duplicate these in program long each "copy" looks exactly same. that's because, historically, compilers inlining on functions visible in same translation unit. nowadays, link-time optimisation exists.
Comments
Post a Comment