title: C++ Undefined, Referenced Variable
body: <p><strong>Issue:</strong>
  I have a common question that I'm trying to solve, but I cannot figure out why the solution I have isn't working. I'm receiving a <a href="https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2001?f1url=%3FappId%3DDev16IDEF1%26l%3DEN-US%26k%3Dk(LNK2001)%26rd%3Dtrue&amp;view=msvc-170" rel="nofollow noreferrer">LNK2001</a> error message for not having <code>numOfShapes</code> properly defined. I think I have it defined, but the compiler thinks otherwise. What am I missing?</p>
  <p><strong>Context:</strong> I'm going through a tutorial, <a href="https://youtu.be/6y0bp-mnYU0?t=2996" rel="nofollow noreferrer">link with timestamp</a>, on building a header file and a polymorphic header file when this error occurred. The variable isn't needed to making the program run, but I would like to know how to make it work for future use.</p>
  <p><strong>Research:</strong> This is a common issue and if you're looking for a similar, but different answer, then read <a href="https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix/12574400#12574400">this post</a>. The linked post will probably solve your related problem. This has definitely helped me in understanding the problem I'm having, I just can't see why it doesn't work.</p>
  <p>Header File: Shape.h</p>
  <pre><code>#ifndef SHAPE_H
  #define SHAPE_H
  
  // Header file
  
  class Shape {
      protected:
          double height;
          double width;
      public:
          static int numOfShapes;
          Shape();
          Shape(double length);
          Shape(double height, double width);
  
          virtual ~Shape();
          void SetHeight(double height);
          double GetHeight();
          void SetWidth(double width);
          double GetWidth();
          static int GetNumOfShapes();
          virtual double Area();  // Virtual allows for dependents to override the use of this function
  };
  
  #endif /* SHAPE_H */
  </code></pre>
  <p>Implementation File: Shape.cpp</p>
  <pre><code>#include &quot;Shape.h&quot;
  
  // Impimentation file
  
  // Shape Creation
  Shape::Shape(double length) { this-&gt;height = length; this-&gt;width = length;}
  Shape::Shape(double height, double width) { this-&gt;height = height; this-&gt;width = width;}
  Shape::Shape() { this-&gt;height = 0; this-&gt;width = 0; }
  
  // Shape Deletion
  Shape::~Shape() = default;
  
  // Get and Set variable inside of Shape Object
  void Shape::SetHeight(double height) {this-&gt;height = height;}
  double Shape::GetHeight() {return height;}
  void Shape::SetWidth(double width) { this-&gt;width = width; }
  double Shape::GetWidth() { return width;}
  
  // Returning total number of shapes
   int Shape::GetNumOfShapes() { return numOfShapes; }  // &lt;-- Source of Error Generation
  
  // Calculating the area when called
   double Shape::Area() {return height * width;}
  
  // Default value
  int numOfShapes = 0; // &lt;-- Not defined here?
  </code></pre>
  <hr />