473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

template question.

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?

Jul 18 '07 #1
3 1275
"tather" <ta****@gmail.comwrote in message
news:11**********************@g12g2000prg.googlegr oups.com...
>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>
Jul 18 '07 #2
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
Jul 18 '07 #3
On Jul 18, 3:54 am, tather <tat...@gmail.comwrote:
I found these code inhttp://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 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:ja*********@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
Jul 19 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dave | last post by:
Hello all, Consider this function template definition: template<typename T> void foo(T) {} If foo is never called, this template will never be instantiated. Now consider this explicit...
1
by: Alfonso Morra | last post by:
if I have a class template declared as ff: (BTW is this a partial specialization? - I think it is) template <typename T1, myenum_1 e1=OK, my_enum_2=NONE> class A { public: A(); virtual...
10
by: Suki | last post by:
Hi, I'm writing a templated class, and i dont want to use the class otherthan for some predetermined types, say, int, double etc. This class has no meaning for typenames other than those few. ...
12
by: mlimber | last post by:
This is a repost (with slight modifications) from comp.lang.c++.moderated in an effort to get some response. I am using Loki's Factory as presented in _Modern C++ Design_ for message passing in...
1
by: Leslaw Bieniasz | last post by:
Hello, I have the following problem: file a.h --------------- template <class T> class A { // some stuff
2
by: pookiebearbottom | last post by:
Just trying to learn some things about templates. Was wondering how boost::tupple really works, but the headers were a bit confusing to me. I know you get do something like the following, just...
45
by: charles.lobo | last post by:
Hi, I have recently begun using templates in C++ and have found it to be quite useful. However, hearing stories of code bloat and assorted problems I decided to write a couple of small programs...
2
by: aitrob | last post by:
Hi, I have a problem concerning templates/inheritance. I have a code that compiles fine with g++ 4.0.1 (Apple version), but gives a lot of errors with Intel C++ 10.1 (Mac OS X). I'm not sure if...
4
by: David Sanders | last post by:
Hi, I have a class with an integer template parameter, taking values 1, 2 or 3, and a function 'calc' in that class which performs calculations. Some calculations need only be performed if the...
3
by: stdlib99 | last post by:
Hi, I have a simple question regarding templates and meta programming. I am going to try and work my way through the C++ Template Metaprogramming, a book by David Abrahams and Aleksey...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.