Search code examples
c++directx-9

A class inherited from a class with fixed data


I'm developing a GUI for directx in C++. I've got a class for my controls:

class cControl;

a class for my windows:

class cWindow : public cControl

and what I want to do is write a class for a special kind of window (color picker).

class cColorPicker : public cWindow

The constructor of the colorpicker class calls only cControl functions. To set things up in the gui routine for every window I use this code this:

for each( cWindow* pWindow in m_vWindows )
    // stuff

What I notice debugging is that position, width, height and every thing I set up in colorpicker constructor results null.

EDIT: what I want to do is having a special window with a constructor that sets up (eg) width, height, etc, of the window. Will this do the work?

cColorPicker::cColorPicker( int x, int y )
{
    cWindow::cWIndow( x, y, ... )
}

EDIT2: second problem: I have to call a function from cWindow class (a function that adds a control to the window) but it seems to give problems too, and I think I have to do it inside of the constructor of cColorPicker.


Solution

  • Your should use member initializer list to initialize base object with parameter

    cColorPicker::cColorPicker(int x, int y)
    : cWIndow( x, y, ... ), width(42),height(42) 
    {
    }
    

    EDIT: If you want to add extra parameter to base constructor, should pass it from cColorPick constructor to its base:

    cColorPicker::cColorPicker(int x, int y, cControl* pControl)
    : cWIndow( x, y, pControl, ...), width(42),height(42) 
    {
    }
    
    // edit or create a new cWindow constructor to accept CControl* parameter
    cWIndow::cWIndow(int x, int y, cControl* pControl)
    :width(x), height(y), m_vControls(pControl)
    {
    }