|
-
July 13th, 2004, 03:55 PM
#1
contructor not allocating array properly?
This is a weird one... not sure why this is happening.
In my .h, in my class, in the public section, I have the following:
in my class constructor, I have:
Code:
useme = new CButton[MAX_WARP_TYPES];
later in my program, I have:
Code:
void myClass::createScreenConfig(CString path,int num)
{
// ....
useme[0].Create(_T(""),WS_CHILD|WS_VISIBLE|BS_CHECKBOX,
CRect(rect.left+leftSpace, rect.top+topAdjust+fieldHeight*0,rect.right-3,rect.top+30),
this,1500);
}
but this causes the following assert from wincore.cpp to fail:
ASSERT(pWnd->m_hWnd == NULL); // only do once
However, if I put the "useme = new CButton[MAX_WARP_TYPES];"
right in the function, it works correctly. What's going on?
-
July 13th, 2004, 04:16 PM
#2
 Originally Posted by ecspansion
This is a weird one... not sure why this is happening.
However, if I put the "useme = new CButton[MAX_WARP_TYPES];" right in the function, it works correctly. What's going on?
It looks like createScreenConfig is called more than once - the assertion fails if you call Create() for a button that has already been created. If you put the new inside your function, you will just hide the bug, since new memory will be allocated before calling Create() every time the function is called.
-
July 13th, 2004, 04:18 PM
#3
Hi ecspansion,
I did not try to run the code, but I would probably approach it as follows:
CButton** ppButton;
*pButton = new CButton[ size ];
then,
pButton[0]->Create( ... )
Jeff
-
July 13th, 2004, 05:05 PM
#4
 Originally Posted by gstercken
It looks like createScreenConfig is called more than once - the assertion fails if you call Create() for a button that has already been created. If you put the new inside your function, you will just hide the bug, since new memory will be allocated before calling Create() every time the function is called.
DOH! There needs to be a ::smacks own head:: icon.
Of course this is what's causing it - I don't know how I didn't see that before.
Thanks!
... now where's that three hours just lost trying to find this bug?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|