c++ - What is the best way to define a double constant in a namespace? -


What is the best way to define double continuous in Namespace? For example

  // constant.h namespace constant {constant constant double PI = 3.1415926535; } // constant.cpp is not needed  

Is this the best way?

I will say:

- c ++ 14:

< Pre> namespace constant {templates & lt; Typename t = double & gt; Constexpr T PI = T (3.1415926535897932385); }

- In c ++ 11:

  namespace constant {constexpr double PI = 3.1415926535897932385; }  

- c ++ 03:

  namespace constant {static const double pi = 3.1415926535897932385; }  

Note that if you do not have any trivial type of continuity and you are in a shared library, then I suggest avoiding giving it internally to the global / namespace I do not know the principle about it but in practice it randomly gets messed up :)


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -