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 . 

  1. static @ namespace scope means "local translation unit", you'll new copy of object in every unit includes header.

  2. same thing.

  3. these have internal linkage default.

  4. 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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -