title: C++ header file variable scope issue
body: <p>I've got 3 files that relate to this problem. file.h, file.C and user.C.</p>
  
  <p>file.h has a private member, fstream logs.</p>
  
  <p>In file.C's constructor it opens logs. It doesn't do this in the constructor, but the constructor calls a function OpenLog().</p>
  
  <p>file.h also has an inline close function:</p>
  
  <blockquote>
    <p>CloseLog() {if (logs) logs.close();}</p>
  </blockquote>
  
  <p>The file user.C has an exit function which creates an instance of file, then calls CloseLog. It seg faults at this point. I created some other dummy tests, and it appears as though logs is lost in the mix somewhere ... </p>
  
  <p>Going from file.C to user.C and then back to file.C causes this. If I have fstream logs as a global in file.C then it works - but I'd rather avoid a global.</p>
  
  <p>Any thoughts on what I should do here? Please let me know if I should post more code about this, I can set up some dummy stuff to demo this better.</p>
  
  <p>**  Here's more code, as requested - I can't copy and paste, so forgive the lack of it please **</p>
  
  <p>I will call the classes helpME.h, helpME.C and user.C</p>
  
  <blockquote>
    <p>//helpME.h<br>
     #ifndef _helpME_H<br>
     #define _helpME_H</p>
    
    <p>#include &lt; iostream><br>
     #include &lt; fstream><br>
    //various includes</p>
    
    <p>class helpME {<br>
    private:<br>
    fstream logs;</p>
    
    <p>public:<br>
    void CloseLog() {if (logs) logs.close();}<br>
    };<br>
      #endif</p>
    
    <p>//end helpME.h</p>
    
    <p>//helpME.C<br>
    void helpME::helpME(int argc, char** argv)<br>
    {<br>
    //various code<br>
    OpenLog();<br>
    }  </p>
    
    <p>void helpME::OpenLog()<br>
    {<br>
    //logname is set above, i had a print statement before that showed this is correct<br>
    logs.open(logname, ios::in | ios::out | ios::trunc);<br>
    }</p>
    
    <p>//end helpME.C  </p>
    
    <p>//user.C<br>
    void user::quitHelpME(item)<br>
    {<br>
    helpME* hME = (helpME*) item;<br>
    hME->CloseLog();<br>
    }  </p>
    
    <p>//end user.C</p>
  </blockquote>
  
  <p>Again - please forgive the lack of clarity, I'm thinking I may have just confused things more by adding this ... this code is on another box and can't be copied over.</p>