title: initializing const variables after the declaration C++
body: <p>I'm trying to declare a constant variable in <code>C++</code>;</p>
  
  <pre><code>        #include &lt;iostream&gt;
          #include &lt;pthread.h&gt;
          #include &lt;stdlib.h&gt;
  
          using namespace std;
  
          //
          // declare the mutex
          //
          static pthread_mutex_t mutex    = PTHREAD_MUTEX_INITIALIZER;
  
          //
          // AVOID NEGATIVE NUMBERS
          //
          unsigned int MAXSIZE = 0;
          unsigned int head = 0;
          unsigned int tail = 0;  
  
          //
          // return a empty circular queue
          //
          int* initialize(int size){
  
             MAXSIZE = size;
             pthread_mutex_lock( &amp;mutex );
             int* queue = new int[ MAXSIZE ];
             // initialize each position to zero ( explicitly )
             for(int i = 0; i &lt; MAXSIZE; i++){
              queue[i] = 0;
             } 
  
             pthread_mutex_unlock( &amp;mutex );
             return queue;
          }
  
          //
          // enqueue number into the queue
          // returns the position it was stored
          //
          void* enqueue( void* local_queue, void* local_data ){
             // ASSERT ONLY ONE THREAD EACH  TIME
             pthread_mutex_lock( &amp;mutex );
             // convert back to int
             int data = *((int*)(&amp;local_data));
             int* queue = (int*)local_queue;
  
             queue[tail] = data;
             tail = (tail+1) % MAXSIZE;
  
             pthread_mutex_unlock( &amp;mutex );
             cout &lt;&lt; "Tail: " &lt;&lt; tail &lt;&lt; endl;
          }
  
          //
          // dequeue, given the queue
          //
          void* dequeue( void* queue ){
             int temp;
             pthread_mutex_lock( &amp;mutex );
             int* local_queue = ( int* )queue; 
             temp = local_queue[ head ];
             head = ( head + 1 ) % MAXSIZE;
  
             pthread_mutex_unlock( &amp;mutex );
             cout &lt;&lt; "Removed: " &lt;&lt; temp &lt;&lt; endl;
      }
  
      // 
      // print the queue as it is
      //
      void* display( void* local_queue ){
         pthread_mutex_lock( &amp;mutex );
         int* queue = (int*)local_queue;
         if( head == tail ){
          cout &lt;&lt; "Queue underflow" &lt;&lt; endl;
         }
         else{
          //
          // prints each element in the queue
          //
          for( unsigned int i = head; i &lt; tail; i = (i+1) % MAXSIZE ){
              cout &lt;&lt; queue[i] &lt;&lt; endl;
          }
         }
         pthread_mutex_unlock( &amp;mutex );
      }
  
      //
      // delete the memory allocated to the queue
      //
      void remove( int* queue){
         delete queue;
      }
  
      //
      // explain the user how to run the program
      //
      void usage(){
        cout &lt;&lt; "Usage: " &lt;&lt; endl; 
        cout &lt;&lt; "    ./queue [size] [elements]" &lt;&lt; endl;
        cout &lt;&lt; "ex: ./queue 5 0 1 2 3 4 5" &lt;&lt; endl;
      }
  
      //
      // main function, the tests are done in the for loop
      //
      int main( int argc, char* argv[] ){
  
         pthread_t threads[5];
  
         if(argc &lt; 2){
          cout &lt;&lt; "Args must be at least 1 " &lt;&lt; endl;
          usage();
          return -1;
         }
  
         for(size_t j = 0; j &lt; 5; j++){   
          unsigned int size = atoi( argv[1] );
          cout &lt;&lt; "Size: " &lt;&lt; size &lt;&lt; endl;
          int* queue = initialize(size);
  
          for(size_t i = 2; i &lt; argc; i++){
              enqueue( queue, (void*)atoi( argv[i] ) );
          }
              pthread_create( &amp;threads[j], NULL, dequeue, (void*)queue );
          // make sure memory is freed 
          // finally end the thread
          pthread_join( threads[j], NULL );
          remove(queue);
         }
         return 0;
      }
  </code></pre>
  
  <p>I would like to have <code>unsigned int MAXSIZE = 0;</code> declared as <code>const unsigned int MAXSIZE;</code> So I could initialize that at <code>runtime</code>. I know it can be done in the constructor of <code>class</code>, however I would like to know whether there is a way to initialize <code>MAXSIZE</code> to <code>size</code> which  is given by the user. <code>MAXSIZE</code> is used to implement the circular queue implemented in an array was shown, so it's important to <code>MAXSIZE</code> to be declared as <code>const</code> to avoid being changed and then affect the <code>circular</code> operation of the queue.
  Thanks.
  *<em>I hope I clarify my question enough to have a more precise answer. I've added all my code into the question for completeness and for the sake of the community. *</em></p>