Destructor called upon creation
Hi...
I've got a small problem. When I declare an instance of the class CWindow, its both - constructor and destructor are called.
Declaration of the class:
Code:
class CWindow
{
public:
CWindow(char* pType, char *pCaption, int x, int y, int cx, int cy, HMENU hId, HWND hParent);
CWindow(HWND hWnd);
CWindow();
~CWindow();
friend class CMainApp;
private:
HWND hwnd;
RECT rect;
};
Fuctions of CWindow:
Code:
CWindow::CWindow(char* pType, char* pCaption, int x, int y, int cx, int cy, HMENU hId, HWND hParent)
{
hwnd = CreateWindowEx(NULL, pType, pCaption, WS_CHILD|WS_VISIBLE, x, y, cx, cy, hParent, hId, hinstance, NULL);
GetClientRect(hwnd, &rect);
}
CWindow::CWindow(HWND hWnd)
{
hwnd = hWnd;
GetClientRect(hwnd, &rect);
}
CWindow::CWindow()
{
}
CWindow::~CWindow()
{
DestroyWindow(hwnd);
}
Use of the class:
Code:
CWindow questionStatic = CWindow("static", pQuestion, 30, 10, 200, 30, NULL, hwnd);
The debugger shows that this line is executed twice. The first execution calls the constructor, the second calls the destructor. I must be missing something very obvious here, but can't find what.