Reputation: 23302
I've spent the past couple of days learning C++, but I just came across something that I hadn't seen in the books nor after doing some research on Google.
As far as I know, a macro is a statement or "variable" name that is preceded by #define
hat allows certain values or functions to be specified later and inserted where desired automatically.
However, I've come across a function that is declared inside a clas and not preceded by #define
and it is called a "macro". The function is from MFC and is called DECLARE_MESSAGE_MAP
.
http://msdn.microsoft.com/en-us/library/08ea0k43.aspx
Can someone explain what this type of macro is; what is it called (so I could further research it) and what does it mean?
Upvotes: 1
Views: 3282
Reputation: 172378
You may find this interesting:-
If you decide to clean up and re- arrange your code, better be careful about the DECLARE_MESSAGE_MAP() macro that will be present in an MFC derived class header file. This macro contains a “protected” storage class declaration. So everything that comes under this macro will be protected unless there is any other storage class specified after that. Normal error that occur during compilation will be cannot access the private variable. But you cannot easily figure out what went wrong you can see only a macro call and a public storage class above.
#ifdef _AFXDLL #define DECLARE_MESSAGE_MAP() \ private: \ static const AFX_MSGMAP_ENTRY _messageEntries[]; \ protected: \ static AFX_DATA const AFX_MSGMAP messageMap; \ static const AFX_MSGMAP* PASCAL _GetBaseMessageMap(); \ virtual const AFX_MSGMAP* GetMessageMap() const; \ #else #define DECLARE_MESSAGE_MAP() \ private: \ static const AFX_MSGMAP_ENTRY _messageEntries[]; \ protected: \ static AFX_DATA const AFX_MSGMAP messageMap; \ virtual const AFX_MSGMAP* GetMessageMap() const; \ #endif
The solution is to leave it inside a protected storage class. i.e, declare a protected storage class just above it and declare the functions and variables that require to be protected, below it. Let the public functions and variables be above the protected section with proper declaration of the storage class.
Upvotes: 0
Reputation: 65476
DECLARE_MESSAGE_MAP is just a #define that is defined in the MFC (Afx.h?) set of includes. there is nothing special about compared to any other #define.
This is an old book : MFC Internals but it's a classic if you want to learn what all those things in the MFC actually do and how they work.
Upvotes: 2