Connecting Tech Pros Worldwide Forums | Help | Site Map

template question.

tather
Guest
 
Posts: n/a
#1: Jul 18 '07
I found these code in http://www.parkscomputing.com
but I can not compile it successful.

------------------------------------------------

typedef LONG (__stdcall * forwardFn_t)(HWND, UINT, WPARAM, LPARAM);
template<UINT msgclass Handler;
template<class Handler<WM_PAINT>
{
protected:
virtual void OnPaint() = 0;
public:
LRESULT Handle(WPARAM wParam, LPARAM lParam)
{
OnPaint();
return 0L;
}
static void Forward(HWND hWnd, forwardFn_t pfn)
{
(*pfn)(hWnd, msg, 0L, 0L);
}
};
----------------------------------------------------
error C2065: 'msg' : undeclared identifier

Why the error occur, and How can I resolve it to get the same fuction?


Jim Langston
Guest
 
Posts: n/a
#2: Jul 18 '07

re: template question.


"tather" <tather@gmail.comwrote in message
news:1184723640.630539.211770@g12g2000prg.googlegr oups.com...
Quote:
>I found these code in http://www.parkscomputing.com
but I can not compile it successful.
>
------------------------------------------------
>
typedef LONG (__stdcall * forwardFn_t)(HWND, UINT, WPARAM, LPARAM);
template<UINT msgclass Handler;
template<class Handler<WM_PAINT>
{
protected:
virtual void OnPaint() = 0;
public:
LRESULT Handle(WPARAM wParam, LPARAM lParam)
{
OnPaint();
return 0L;
}
static void Forward(HWND hWnd, forwardFn_t pfn)
{
(*pfn)(hWnd, msg, 0L, 0L);
}
};
----------------------------------------------------
error C2065: 'msg' : undeclared identifier
>
Why the error occur, and How can I resolve it to get the same fuction?
It most likely means it doesn't know what UINT means, so msg is undeclared.
It's common for some compilers to give an error on the next line, or next
syntax word it finds.

I'm sure if you do:
typedef unsigned int UINT;
before that line it will get past that error, but then it'll probably bitch
about <WM_PAINTetc... This is windows code and expects windows headers.
Try including <windows.h>


Bo Persson
Guest
 
Posts: n/a
#3: Jul 18 '07

re: template question.


tather wrote:
:: I found these code in http://www.parkscomputing.com
:: but I can not compile it successful.
::
:: ------------------------------------------------
::
:: typedef LONG (__stdcall * forwardFn_t)(HWND, UINT, WPARAM, LPARAM);
:: template<UINT msgclass Handler;
:: template<class Handler<WM_PAINT>
:: {
:: protected:
:: virtual void OnPaint() = 0;
:: public:
:: LRESULT Handle(WPARAM wParam, LPARAM lParam)
:: {
:: OnPaint();
:: return 0L;
:: }
:: static void Forward(HWND hWnd, forwardFn_t pfn)
:: {
:: (*pfn)(hWnd, msg, 0L, 0L);
:: }
:: };
:: ----------------------------------------------------
:: error C2065: 'msg' : undeclared identifier
::
:: Why the error occur, and How can I resolve it to get the same
:: fuction?

The name msg is the template parameter of the Handler class. In the
specialization of this class, you just have template<>, and the msg
name isn't visible. In this case, its value is WM_PAINT, as this is
what it is specialized for.

That it once used to compile is really a bug that has been fixed in
later editions if the compiler!



Bo Persson


James Kanze
Guest
 
Posts: n/a
#4: Jul 19 '07

re: template question.


On Jul 18, 3:54 am, tather <tat...@gmail.comwrote:
Quote:
I found these code inhttp://www.parkscomputing.com
but I can not compile it successful.
Quote:
------------------------------------------------
Quote:
typedef LONG (__stdcall * forwardFn_t)(HWND, UINT, WPARAM, LPARAM);
template<UINT msgclass Handler;
template<class Handler<WM_PAINT>
{
protected:
virtual void OnPaint() = 0;
public:
LRESULT Handle(WPARAM wParam, LPARAM lParam)
{
OnPaint();
return 0L;
}
static void Forward(HWND hWnd, forwardFn_t pfn)
{
(*pfn)(hWnd, msg, 0L, 0L);
}
};
----------------------------------------------------
error C2065: 'msg' : undeclared identifier
Quote:
Why the error occur, and How can I resolve it to get the same fuction?
The error occured (obviously) because there is no symbol msg
declared which is visible in the scope of the function. In
fact, the only symbol msg I see anywhere is as an argument to
the template declaration; since it is a declaration, and not a
definition, the symbol is really only a comment, and not
accessible anywhere.

What did you mean instead of msg? WM_PAINT? Or something else?

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


Closed Thread


Similar C / C++ bytes