Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MESSAGE_MAP in template class

Posted on 2002-03-12
5
Medium Priority
?
435 Views
Last Modified: 2008-03-10
I have a small problem, how to write MESSAGE_MAP in template class. I've something like "template <class DLGCLASS> class CMyComboBox : public CComboBox" and I don't know how to write "BEGIN_MESSAGE_MAP(???, CComboBox)". I want only to know how (and if) I can do it, no how to do it by another way f.e. as not template class. Thanks.
0
Comment
Question by:lonicekm
5 Comments
 
LVL 2

Expert Comment

by:gandalf79
ID: 6860142
you would write something like:

BEGIN_MESSAGE_MAP(CMyComboBox<DLGCLASS>, CComboBox)
     ...
END_MESSAGE_MAP()

the compiler will make a new copy of CMyComboBox each time you place a new variable type into the class. DLGCLASS will be replaced at that time with the apropreate type.
0
 

Author Comment

by:lonicekm
ID: 6860311
Did u try it? Sure I tried this possibility and

error C2065: 'DLGCLASS' : undeclared identifier
error C2955: 'CMyComboBox' : use of class template requires template argument list
error C2039: '_GetBaseMessageMap' : is not a member of 'CMyComboBox'
...
and many others.
0
 
LVL 2

Accepted Solution

by:
gandalf79 earned 400 total points
ID: 6862041
sorry for the bad info i was up late last night and was not thinking strait.

this is the definition for BEGIN_MESSAGE_MAP.

#define BEGIN_MESSAGE_MAP(theClass, baseClass) \
     const AFX_MSGMAP* theClass::GetMessageMap() const \
          { return &theClass::messageMap; } \
     AFX_COMDAT AFX_DATADEF const AFX_MSGMAP theClass::messageMap = \
     { &baseClass::messageMap, &theClass::_messageEntries[0] }; \
     AFX_COMDAT const AFX_MSGMAP_ENTRY theClass::_messageEntries[] = \
     { \

you must retype this. you cant use the macros! the first function need to look like this

template <class DLGCLASS> const AFX_MSGMAP* CMyComboBox<DLGCLASS>::GetMessageMap() const
     { return &CMyComboBox<DLGCLASS>::messageMap; }

the lack of "template <class DLGCLASS>" before GetMessageMap() function is causing the error C2065 and C2955.

you may also have to rewrite other macros in the class like IMPLEMENT_DYNCREATE etc. in the same manner.

this is all i have time for right now but let me know how this works out for you and ill get back to you if you need any more help.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6955344
Dear lonicekm

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "gandalf79"

comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 6979078
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question