Is this not legal syntax?

This is a discussion on Is this not legal syntax? within the C++ Programming forums, part of the General Programming Boards category; Ok, what about declaring the array in the class def. and then initializing it in the constructor for the class ...

  1. #16
    Registered User
    Join Date
    May 2002
    Posts
    317
    Ok, what about declaring the array in the class def. and then initializing it in the constructor for the class aka:

    CDialog::CDialog()
    {
    unsigned int m_iPageNames[] ={IDD_COLORS,IDD_KEYWORDS, IDD_OPERATORS};

    }
    Last edited by Traveller; 05-05-2002 at 09:42 AM.

  2. #17
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Wouldn't that make the variable local to the constructor?

  3. #18
    Registered User
    Join Date
    May 2002
    Posts
    317
    Not to my knowledge, I believe if you first define it in the class aka

    unsigned int m_iPageNames[3];

    then just initialize it in the constructor then you just simply apply values to it their and not define it. As far as I understand the constructor is used for situations like this when you want to initialize variables when the object is being created.

  4. #19
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Bah, I got it
    I just made the variable local to OnInitDialog

    Code:
    BOOL CColorCoderDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    
    	// Add "About..." menu item to system menu.
    
    	// IDM_ABOUTBOX must be in the system command range.
    	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    	ASSERT(IDM_ABOUTBOX < 0xF000);
    
    	CMenu* pSysMenu = GetSystemMenu(FALSE);
    	if (pSysMenu != NULL)
    	{
    		CString strAboutMenu;
    		strAboutMenu.LoadString(IDS_ABOUTBOX);
    		if (!strAboutMenu.IsEmpty())
    		{
    			pSysMenu->AppendMenu(MF_SEPARATOR);
    			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    		}
    	}
    
    	// Set the icon for this dialog.  The framework does this automatically
    	//  when the application's main window is not a dialog
    	SetIcon(m_hIcon, TRUE);			// Set big icon
    	SetIcon(m_hIcon, FALSE);		// Set small icon
    
    	unsigned int iPageNames[] = {IDD_COLORS, IDD_KEYWORDS, IDD_OPERATORS};
    	for (int i = 0; i < (sizeof(m_ppPages) / sizeof(CPropertyPage)); i++)
    	{
    		
    		m_ppPages[i].Construct(iPageNames[i], 0);
    		m_psSheet.AddPage(&m_ppPages[i]);
    	}
    	m_psSheet.Create(this, WS_CHILD | WS_VISIBLE, 0);
    	m_psSheet.ModifyStyleEx(0, WS_EX_CONTROLPARENT);
    	m_psSheet.ModifyStyle(0, WS_TABSTOP);
    
    	CRect rect;
    	GetWindowRect(&rect);
    	ScreenToClient(&rect);
    	m_psSheet.SetWindowPos(NULL, rect.left + 7, rect.top + 150, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
    
    	return TRUE;  // return TRUE  unless you set the focus to a control
    }
    Edit:: Thanks for all the help Traveller
    Last edited by Dual-Catfish; 05-05-2002 at 10:00 AM.

  5. #20
    Registered User InFeStEd-ArCh0n's Avatar
    Join Date
    Apr 2002
    Posts
    63
    I still think the compiler should accept that. It would make some people happy.
    -Mike
    {InFeStEd-ArCh0n}

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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