contructor not allocating array properly?

This is a discussion on contructor not allocating array properly? within the Windows Programming forums, part of the Platform Specific Boards category; This is a weird one... not sure why this is happening. In my .h, in my class, in the public ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    72

    constructor 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:

    Code:
      CButton* useme;
    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?
    Last edited by BrianK; 07-13-2004 at 12:06 PM.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    useme[0]->Create
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    72
    Quote Originally Posted by Ken Fitlike
    useme[0]->Create
    at the point that I'm using it, "useme" points to an array, so useme[x]->func() would be incorrect... being that the subscipt gets you to an actual memory location.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Good lord! Sorry about that - kenf and his lumpy spam-for-brains strikes again.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    72

    as it turns out, "createScreenConfig" gets called more than once, and even though I pass "num" in so that I don't create the same thing twice, my test was using [0] instead of [num], so create was getting called twice on the same button.

    the fix: useme[num].Create(yada,yada,yada);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  3. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM
  4. Creating 2D arrays on heap
    By sundeeptuteja in forum C++ Programming
    Replies: 6
    Last Post: 08-16-2002, 11:44 AM
  5. Replies: 4
    Last Post: 09-12-2001, 02:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21