Solved

MESSAGE_MAP in template class

Posted on 2002-03-12
5
414 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 100 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

718 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