title: Why do I need to instantiate an object in C#, but not in C++ in order to access a class's functions?
body: <p>I have recently began programming in C# for Unity(game engine) development. I noticed that unlike C++; C# requires me to instantiate an object on the heap before using its member functions or variables. Where as with C++ I can declare an object and call any function from the declaration name.</p>
  
  <p>C++ Example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  class SampleClass 
  
  {
     void PrintFunc()
     {
        cout&lt;&lt;"Hello World"&lt;&lt;endl;
     }
   }
  
  int main()
  {
  
     SampleClass objectC; //Object declaration
     objectC.PrintFunc(); //Use of function without instantiation
  
     //The above code will print'Hello World'
  }
  </code></pre>
  
  <p>C# Example:</p>
  
  <pre><code> using System
  
   namespace ConsoleProject2
  {
      class MainClass
     {
  
     class SampleClass
     {
          Void PrintFunc()
          {
            Console.WriteLine("Hello World");
          }
      }
  
      public static void Main (string[] args)
      {
  
          SampleClass objectC = new SampleClass();
          //Must instantiate before accessing member functions 
          objectC.PrintFunc(); //Prints out 'Hello World'
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Reading on Unity's <a href="https://docs.unity3d.com/Manual/UnderstandingAutomaticMemoryManagement.html" rel="nofollow">Automatic Memory Management</a> website I was only able to conclude that due to it's automatic garbage collection it may require you to place new objects on the heap since it deallocates them for you. (May be a false assumption, please correct me) </p>
  
  <p>Why do these two languages differ when it comes to accessing an objects properties? Is the object in C++ being placed on the stack since there is no instantiation; if so why not place all objects on the stack?</p>
  
  <p>Thank you.</p>