title: C++ deque throwing Segfaults
body: <p>I have some code from a project which doesn't seem to be working. </p>
  
  <p>I am trying to make a deque (of a struct) which is a static member of a class.
  The skeleton/basic code is as follows (I have retained all datatypes - my_typedef_fn is a data type got by typedef-ing a function pointer) :</p>
  
  <p>1.h file : </p>
  
  <pre><code>class A {
      struct Bstruct {
          char * b_name;
          my_typedef_fn b_func;
      }
      static std::deque&lt;Bstruct&gt; a_deque;
      static void func();
  }
  </code></pre>
  
  <p>1.cpp file :</p>
  
  <pre><code>std::deque&lt;A::Bstruct&gt; A::a_deque;
  void A::func(char * name, my_typedef_fn fn) {
      a_deque.push_front((Bstruct) {name, fn} ); // &lt;&lt;&lt;&lt; segfault !
  } 
  </code></pre>
  
  <p>From my understanding
   - The .h file just declares the stuff (as usual)
   - The first line in the .cpp initializes the static member a_deque
   - The function func adds stuff to the deque using push_back</p>
  
  <p>But I get a Segmentation Error at the line where push_front is called (found this using gdb).</p>
  
  <p>Also, when I print a_deque.size() before push_front I get 4294967264 before the SEGFAULT
  And when I count the number of elements in deque using a for loop : </p>
  
  <pre><code>int counter = 0
  for( std::deque&lt;Bstruct&gt; it = a_deque.begin(); it != a_deque.end(); it++, counter++ );
  </code></pre>
  
  <p>my counter shows 0 elements to be in the </p>
  
  <p>So, I do not understand why I get a segfault nor why the .size() is a large garbage number</p>
  
  <p>-- EDIT 1 --
  Adding the way the functions are called :</p>
  
  <p>2.cpp</p>
  
  <pre><code>#include "1.h"
  void fn1() { 
      // some code
  }
  A::func("abc", fn1);
  </code></pre>
  
  <p>It is complied with the commands :</p>
  
  <pre><code>g++ -c -w -fpermissive -o 1.o 1.cpp
  g++ -c -w -fpermissive -o 2.o 2.cpp
  g++ -o final 1.o 2.o
  </code></pre>