title: C++: Keep track of times function is called
body: <p>Keeping track of how many times a function is called is easy when passing the counter as an argument into the function.  It's also easy when returning a one from the called function.  But, I do not want to go that route.  The reason behind this is because it seems like bad programming (letting the function know too much information).  Is there a better way to keep track of how many times this function has been called?</p>
  
  <p>I'm just looking for concepts that I could study.  Providing code examples is not neccessary, but might be helpful.</p>
  
  <p>Edit:  I'm not actually looking for profiling tools.  Let me add some code to get my point across.  Because scope for funcCounter ends in main, I have no way of getting back a variable from myFunction that will increment funcCounter.  I could possibly return 1 from myFunction and then increment funcCounter that way, but this doesn't seem like very good programming.  Is there another way to do it?</p>
  
  <pre><code>int main()
  {
  int funcCounter = 0;
  char *mystring = "This is a silly function.";
  myFunction(mystring);
  cout &lt;&lt; "Times function is called: " &lt;&lt; funcCounter &lt;&lt; endl;
      return 0;
  }
  
  void myFunction(char *mystring)
  {
  cout &lt;&lt; mystring &lt;&lt; endl;
  }
  </code></pre>