title: How to access static member of a 'struct' in another source file
body: <p>I'm creating a small program to do billing. I'm trying to access a static member static double total declared in a header file, in another source file. Java is my first language so having trouble in sorting it out in C++.</p>
  <p>When I try i get the following error.</p>
  <blockquote>
  <p>bill.cpp(16): error C2655: 'BillItem::total': definition or redeclaration illegal in current scope</p>
  <p>bill.h(8): note: see declaration of 'BillItem::total'</p>
  <p>bill.cpp(16): error C2086: 'double BillItem::total': redefinition</p>
  <p>bill.h(8): note: see declaration of 'total'</p>
  </blockquote>
  <p>How can I make it available. Googling the error didn't help.</p>
  <p>What i want is to implement is to create a static double variable in a struct which will be common to all struct instances. I need to access this static variable in another source file where I will be doing the calculation.</p>
  <p>Bill.h</p>
  <pre><code>#pragma once
  
  struct BillItem
  {
  public:
      static double total;
      int quantity;
      double subTotal;
  };
  </code></pre>
  <p>Bill.cpp</p>
  <pre><code>#include&lt;iostream&gt;
  #include &quot;Item.h&quot;
  #include &quot;Bill.h&quot; 
  
  void createBill() {
      double BillItem::total = 10;
      cout &lt;&lt; BillItem::total &lt;&lt; endl;
  }
  </code></pre>
  <p>MainCode.cpp</p>
  <pre><code>#include &lt;iostream&gt;
  #include &quot;Bill.h&quot;
  
  int main() {
      createBill();
      return 0;
  }
  </code></pre>