How to use structures within a class correctly?

Usage: VS2008, Win32, C / C ++

I am trying to encapsulate my entire dialog box into a class for reuse. This is similar to user control. In doing so, I move my individual functions to the class. The following structure design, although it gives me problems with Visual Studio issuing: error C2334 '{'.

This is a simple message card layout. But I can not avoid this error C2334 .: (

Here is my snippet of class code.

class CScrollingListDlg
{
private:

LRESULT DoCommandMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
LRESULT DoPaintMain   (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
LRESULT DoAnimationTimer (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
LRESULT DoHandleTouch (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
LRESULT DoDestroyMain (HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);

//
// message maps
//
// Generic defines and data types.
struct decodeUINT {
    UINT Code;
    LRESULT (*Fxn)(HWND, UINT, WPARAM, LPARAM);
};

struct decodeCMD {
    UINT Code;
    LRESULT (*Fxn)(HWND, WORD, HWND, WORD);
};

// WM_Message dispatch table for MainWndProc.

//
// ***  error C2334 '{'  ***
//
const struct decodeUINT MainMessages[] = {
    WM_PAINT,   DoPaintMain,
    WM_DESTROY, DoDestroyMain,
    WM_QUIT,    DoDestroyMain,
    WM_COMMAND, DoCommandMain,
};


};

What am I missing here?

Thanks.

+3
source share
2 answers

- static - , ... , const ++ (. ).

MainMessages CScrollingListDlg (, , ), static, :

static const decodeUINT MainMessages[];  // "struct" keyword unnecessary

CScrollingListDlg, :

const CScrollingListDlg::decodeUINT CScrollingListDlg::MainMessages[] = {
    WM_PAINT,   DoPaintMain,
    WM_DESTROY, DoDestroyMain,
    WM_QUIT,    DoDestroyMain,
    WM_COMMAND, DoCommandMain,    // The comma *is* allowed -- thanks Josh!
};

, DoPaintMain(), DoDestroyMain() .. static, - , , this, LRESULT (*Fxn)(HWND, UINT, WPARAM, LPARAM). ( decodeUINT , , , , .)

[EDIT: !]

+5

. MainMessages, .

std::vector . , decodeUINT :

std::vector<decodeUINT> MainMessages;

std::vector:: push_back .

, , & MainMessages [0].

+5

Source: https://habr.com/ru/post/1706743/


All Articles