title: Hiding variables in a namespace C++
body: <p>I have a function which aims to perform a recursive calculation. If my function is programmed recursively, it takes too long to compute. Therefore, I perform memoization by storing intermediate results in an array.</p>
  
  <p>During the execution of my program, I might call the function with parameters <code>(10,0)</code>,<code>(5,5)</code>,<code>(2,4)</code> etc. Therefore I have a <code>setup(double x)</code> function which fills the entire array with the correct values. I can then access any of the array values without any further calculations. I only wait until <code>x</code> changes to call <code>setup()</code> again.</p>
  
  <p>I am wondering how I can go about implementing this in c++. It doesn't make sense to me to use a class, as I would never need to create the associated object. I have implemented the functions fine in a namespace, but I'm still having a problem. Even If I use an unnamed namespace, the array used by my function is visible and can be modified from outside the namespace of the function. If I include the header file of the namespace, that is.</p>
  
  <p>my code:</p>
  
  <p><strong>FunctionWrapper.h</strong></p>
  
  <pre><code>namespace FunctionWrapper{
        namespace{
              double tempArray[10][10];
        }
  
        void setup(double x);
        void getValues(int n);
  }
  </code></pre>
  
  <p><strong>Main.cpp</strong></p>
  
  <pre><code>#include "FunctionWrapper.h"
  
  int main(){
     FunctionWrapper::tempArray[0][0] = 5; //Works
  }
  </code></pre>