Solved

MESSAGE_MAP in template class

Posted on 2002-03-12
5
372 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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

808 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