title: Static Functions in C++
body: <p>I've read a few posts on here about static functions, but still am running into trouble with implementation.</p>
  
  <p>I'm writing a hardcoded example of Dijkstra's algorithm for finding the shortest path. </p>
  
  <p>Declared in Alg.h:</p>
  
  <pre><code>static void dijkstra();
  </code></pre>
  
  <p>Defined in Alg.cpp:</p>
  
  <pre><code>static void Alg::dijkstra() { 
  
  //Create Map
  Initialize();
  
  //Loop to pass through grid multiple times
  for(int i=0; i&lt;5; i++)
  {   
      current=1;  
      while(current!=6)
      {
          //Iterate through and update distances/predecessors
          //For loop to go through columns, while current iterates rows
          for(int j=1; j&lt;7; j++)
          {
              //Check if distance from current to this node is less than
              //distance already stored in d[j] + weight of edge
  
              if(distanceArray[current][j]+d[current]&lt;d[j])
              {
                  //Update distance
                  d[j] = distanceArray[current][j]+d[current];
                  //Update predecessor
                  p[j] = current;
              }    
          }
          //Go to next row in distanceArray[][]
          current++;
      } //End while
  
  
  } //End for
  
  output();
  } //End Dijkstras
  </code></pre>
  
  <p>I want to call my function from main <strong>without an object</strong>. When I had all of this code in Main.cpp, it worked perfectly. Splitting it up into separate files caused  the error <code>Main.cpp:15: error: ‘dijkstra’ was not declared in this scope</code>.The posts I came across when searching SE gave me me the impression that to do this, I needed to make that method static, yet I still have no luck. </p>
  
  <p>What am I doing wrong?</p>
  
  <p>Main.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Alg.h"
  
  int main() { 
  
      dijkstra();
      return 0; 
  }
  </code></pre>
  
  <p>Edit: Added full header file, Alg.h:</p>
  
  <pre><code>#ifndef Alg_
  #define Alg_
  
  #include &lt;iostream&gt;
  #include &lt;stack&gt;
  
  using namespace std;
  
  class Alg
  {
      public:
          void tracePath(int x);
          void output();
          void printArray();
          void Initialize();
          static void dijkstra();
          int current, mindex;
          int distanceArray[7][7]; //2D array to hold the distances from each point to all others
          int d[6]; //Single distance array from source to points
          int p[6]; //Array to keep predecessors 
          int copyD[6]; //Copy of d[] used for sorting purposes in tracePath()
          int order[6]; //Contains the order of the nodes path lengths in ascending order
  
  }; //End alg class
  
  #endif
  </code></pre>
  
  <p>Original all-in-one working Main.cpp file: <a href="http://pastebin.com/67u9hGsL">http://pastebin.com/67u9hGsL</a></p>