title: C++ Static Methods (In different Classes) (Like Java's)
body: <p>How would I go about making static methods that are used like the static methods in java when I have multiple .cpp files?</p>
  
  <p>In java you can reference another class by using MyClass name = new MyClass(); and every variable in this class will be the same when called in any other file that you have.</p>
  
  <p>I seems like a pain to have to be able to pass by reference the MyClass&amp; name in every function you want to use that class in.</p>
  
  <p>Is there a way to define MyClass name at the top of a .cpp file without it making a brand new instance of that object in memory and wiping away all of your progress, for example if you were trying to make a simple counter, and the main class would tell the counting class to increment, and the visibility class would get the number of counts from the counting class and print it to the screen. Now this would be simple in that you could pass the counting class to the visibility, but what if you had 20+ methods, then it would be difficult to keep track of.</p>
  
  <p>I'm just not that familiar with static, or references, and I have looked around and saw "namespace", but I am not sure where I would define this, or if it is what I even need.</p>
  
  <p>Thanks in advance</p>
  
  <p>Example Java Code:</p>
  
  <pre><code>public class Foo{
  private static int counter = 0;
  
  public int getCounter(){
      return counter;
  }
  
  public void incrCounter(){
      counter+=1;
  }
  }
  
  public class MainProg{
  public static void main(String[] args){
      Foo foo = new Foo();
      Display disp = new Display();
      foo.incrCounter();
      foo.incrCounter();
      disp.displayCounter();
  }
  }
  
  public class Display{
  Foo foo = new Foo();
  public void displayCounter(){
      foo.incrCounter();
      System.out.println(foo.getCounter());
  }
  }
  </code></pre>
  
  <p>This should print out "3"</p>