title: Why can't we call a function in C++ before declaring it but we can do it in Java?
body: <p>C++ Program:</p>
  <pre><code>#include&lt;iostream&gt;
  
  int main(){
      sayHello();
  }
  
  void sayHello(){
      std::cout &lt;&lt; &quot;Hello\n&quot;;
  }
  </code></pre>
  <p>Output:</p>
  <pre><code>main.cpp: In function 'int main()':
  main.cpp:4:5: error: 'sayHello' was not declared in this scope
       sayHello();
       ^~~~~~~~
  </code></pre>
  <p>Java Program:</p>
  <pre><code>public class Main
  {
      public static void main(String[] args) {
          sayHello();
      }
      
      public static void sayHello(){
          System.out.println(&quot;Hello&quot;);
      }
  }
  </code></pre>
  <p>Output:</p>
  <pre><code>Hello
  </code></pre>
  <p>Is it just because Java provides support to resolve any dependencies among functions during compilation but C++ does not. If yes, Is there a specific reason that C++ did not provide this feature?</p>