pi out of function value

Hello!
In this example, variable pi is declared out of the function value, but in the same namespace.

Is it authomatically entering the function then?

Many thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  // namespaces
#include <iostream>
using namespace std;

namespace foo
{
  int value() { return 5; }
}

namespace bar
{
  const double pi = 3.1416;
  double value() { return 2*pi; }
}

int main () {
  cout << foo::value() << '\n';
  cout << bar::value() << '\n';
  cout << bar::pi << '\n';
  return 0;
}
It should be globally accessible within the namespace. (yes)
Why don't you just try it out ;)
Last edited on
Thanks, that's it!
Topic archived. No new replies allowed.