title: Type cast operator overload of HWND returns trash instead of expected member value
body: <p>I defined a class that I want to use for building a window.  One of the fields is hWnd and when the member function create() is called the HWND to the created window is stored there.  I overloaded the (HWND) cast to return that value:</p>
  
  <pre><code>operator HWND() { return(hWnd); }
  </code></pre>
  
  <p>My program started crashing when I attempted to create child windows to the first, main window I created and I tracked it down to an odd value being returned by the typecast.  I defined a typical getter function, getHwnd(), that works fine but the typecast just returns trash.  Is there something that I'm missing?</p>
  
  <p>The class definition:</p>
  
  <pre><code>class WindowBuilder
  {
  public:
      WindowBuilder(FullWindow &amp;fullWindow);
      operator HWND()                               { return(hWnd); }
      void SetCaption(char const * caption)         { windowName = caption; }
      void SetMenu(int resourceId);
      void SetRender(RECT rect, HWND parent);
      void SetButton(HWND parent);
      void Create();
      void Show(int nCmdShow = SW_SHOWNORMAL);
      HWND getHwnd ()                               { return(hWnd); }
  
  protected:
      FullWindow &amp;        window;
      HWND            hWnd;
      char const *        windowName;
      DWORD           style;
      int         x;
      int         y;
      int         width;
      int         height;
      HWND            hWndParent;
      HMENU           hMenu;
      void *          data;
  };
  </code></pre>
  
  <p>Example of calling: </p>
  
  <pre><code>FullWindow renderWindowClass("STATIC", GlobalInstance, WndProc);
  renderWindow = new WindowBuilder(renderWindowClass);
  renderWindow-&gt;SetRender(rect,mainWindow-&gt;getHwnd());    // used to be (HWND)mainWindow 
  renderWindow-&gt;Create();
  renderWindow-&gt;Show(CmdShow);
  
  /*RenderWindow = ::CreateWindow("STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,
      DEFAULT_BUTTON_WIDTH, 0, rect.right-rect.left-DEFAULT_BUTTON_WIDTH,
      rect.bottom - rect.top, Window, NULL, hInstance, NULL);*/
  </code></pre>