title: Counting how many times a function is called
body: <p>I want to count how many times a function is called, so that if it is called more than once, some error is notified to the developers (via logging, or asserting, and so on). I would like this code to be well defined and isolated so that it is easily portable across many function and member functions as well. Something as easy as:</p>
  
  <pre><code>void function( )
  {
      if( is_called_more_than_once( ) )
      {
          // do something to handle the error
      } 
  }
  
  void AClass::method( )
  {
      if( is_called_more_than_once( ) )
      {
          // do something to handle the error
      } 
  }
  </code></pre>
  
  <p>Is it possible in C++, since it does not have reflection, to achieve something like that somehow?</p>