0

Headers:

This tutorial explains why not to use unnamed namespaces in headers.

That's why we get two options to declare non-member functions in headers: Named namespace vs Inline functions.

Explain please:

When do you use each?

What's the right way to use them?

  • If Named namespace then declaration in header and definition in cpp?
  • If Inline then declaration + definition in the header?

Cpp:

I read that using unnamed namespace is useful only in cpp and it can help to make names internal in the translation unit and avoid name collisions.

If there are any cases to use named namespaces or inline functions in cpp?

Santosh b
  • 729
  • 1
  • 8
  • 19
Gusev Slava
  • 2,136
  • 3
  • 21
  • 26
  • There is no `VS` inbetween `Named namespace` and `Inline functions`. – user7860670 Jul 27 '18 at 19:16
  • @VTT change to "or" – Gusev Slava Jul 27 '18 at 19:19
  • This writeup is fubar. – Swordfish Jul 27 '18 at 19:24
  • 3
    My point is that `named namespaces` and `inline functions` are separate, unrelated concepts that should not be threated as alternatives. Also I must mention that that tutorial is rather misleading in several ways and their suggestion to not define an unnamed namespace in a header file (and "compliant " examples) are conceptually wrong. Spawning separate entities in each translation unit could be a desired behavior while spreading `extern` globals is typically not a good idea. – user7860670 Jul 27 '18 at 19:28
  • Just spotted your links. You should make them stand out better. We of the bad colour vision easily miss one-word links. – user4581301 Jul 27 '18 at 19:32
  • 1
    It looks like you want the difference between anonymous namespaces and inline namespaces, not inline functions. – user4581301 Jul 27 '18 at 19:33
  • @VTT And what are the correct suggestions? – Gusev Slava Jul 27 '18 at 20:26

0 Answers0