I have a method in a parent class that does this:
HWND SppTab::CreateToolTip(HWND hDlg)
{
LRESULT added, active;
const int Controls[] = {
/* Audio Tab (IDD_AUDIO ) */
IDC_AUD_AUTO, IDC_AUD_8, IDC_AUD_16, IDC_CH_AUTO, IDC_LEFT, IDC_RIGHT, IDC_LEVEL_L, IDC_LEVEL_R, IDC_LEVEL_M,
/* Transmitter Tab (IDD_DECODE) */
IDC_DEC_AUTO, IDC_BTN_SCAN, IDC_LIST_PPM, IDC_LIST_PCM,
IDC_CH1, IDC_CH2, IDC_CH3, IDC_CH4, IDC_CH5, IDC_CH6, IDC_CH7, IDC_CH8, IDC_CH9, IDC_CH10, IDC_CH11, IDC_CH12, IDC_CH13, IDC_CH14, IDC_CH15, IDC_CH16
};
// Loop on all controls that require tooltip
for (auto ctrl : Controls)
{
HWND hwndTool = GetDlgItem(hDlg, ctrl);
toolInfo.uId = (UINT_PTR)hwndTool;
added = SendMessage(m_hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
active = SendMessage(m_hwndToolTip, TTM_ACTIVATE, TRUE, (LPARAM)&toolInfo);
};
}
return m_hwndToolTip;
}
The only difference between the derived methods is the content of array Controls[]. Seems like the array should be a member of the derived classes, and will be initialized differently. Note that the array size is not fixed.
How do I initialize an array which is a class member? I know I can define global arrays (for each class) and assign them in the constructors. Is this that best way to go?
+++++++++++++++++++++++ EDIT ++++++++++++++++++++++++++
Well, you can always define a global array const int g_RawBarId[] =
{IDC_CH1,IDC_CH2,IDC_CH3,IDC_CH4,IDC_CH5,IDC_CH6,IDC_CH7,IDC_CH8,\
IDC_CH9,IDC_CH10,IDC_CH11,IDC_CH12,IDC_CH13,IDC_CH14,IDC_CH15,IDC_CH16};
and then assign it to a vector in the constructor:
m_vRawBarId(g_RawBarId, g_RawBarId+sizeof(g_RawBarId)/ sizeof(int))
However, using globals feels like breaking the rules of the OO game.
If you have a better idea - an example will be invaluable.
std::vector.