title: C++ *LPCSTR weird scope error
body: <p>I currently have a class called TextureObject. In the creation function I create the texture, and assign a LPCSTR in the class to a parameter given in the function. When I return that LPCSTR later, it returns in an unexpected manner.</p>
  
  <p>Some type names and functions are from DirectX 11, just ignore them.</p>
  
  <p>Code:</p>
  
  <p>The h File:</p>
  
  <pre><code>class TextureObject
  {
  public:
      ID3D11ShaderResourceView *pTexture;
      LPCSTR GetFilename() const { return *FFilename; }
  
      bool IsNotNull;
      void CreateTexture(ID3D11Device &amp;dev,LPCSTR Filename);
      void ReCreate(ID3D11Device &amp;dev);
      void Release();
      int relativeId;
  private:
      LPCSTR *FFilename;
  };
  </code></pre>
  
  <p>The cpp file:</p>
  
  <pre><code>void TextureObject::CreateTexture(ID3D11Device &amp;dev,LPCSTR Filename)
  {
      D3DX11CreateShaderResourceViewFromFile(
              &amp;dev,        // the Direct3D device
              Filename,    // load Wood.png in the local folder
              NULL,        // no additional information
              NULL,        // no multithreading
              &amp;pTexture,   // address of the shader-resource-view
              NULL);       // no multithreading
      FFilename = new LPCSTR(Filename);
      IsNotNull = true;
  }
  
  void TextureObject::ReCreate(ID3D11Device &amp;dev)
  {
      CreateTexture(dev, *FFilename);
  }
  </code></pre>
  
  <p>When using vs 2012 debugger in the CreateTexture function, the Filename debugger values are:</p>
  
  <pre><code>0x0a06fed0 "C:\Users\Utilizador\Desktop\particle.png"
  </code></pre>
  
  <p>Which is perfect for me! When i assign the class's FFilename:</p>
  
  <pre><code>FFilename = new LPCSTR(Filename);
  </code></pre>
  
  <p>It's ok. When I check the value of FFilename within the scope of this function, it's the same  value of the Filename. But when i use GetFilename, things start getting crazy:</p>
  
  <pre><code> = 0x0a06fed0 "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþü =I.C"
  </code></pre>
  
  <p>Mmm, I just met you, and this is crazy, but... Here's my value. mKay?</p>
  
  <p>Well, please help me. Thank You</p>