///////////////////////////////////////////////
// CIOMessageMap.h
class __declspec(novtable) CIOMessageMap
{
public:
virtual bool ProcessIOMessage(IOType clientIO, ClientContext*
pContext, DWORD dwSize) = 0;
};

#define BEGIN_IO_MSG_MAP() \
public: \
bool ProcessIOMessage(IOType clientIO, ClientContext* pContext, DWORD
dwSize = 0) \
{ \
bool bRet = false;

#define IO_MESSAGE_HANDLER(msg, func) \
if (msg == clientIO) \
bRet = func(pContext, dwSize);

#define END_IO_MSG_MAP() \
return bRet; \
}


Why class CIOMessageMap should be declared by declspec(novtable)?
The macros implements the member function of CIOMessageMap --
ProcessIOMessage();But in other places of project,there no any
inheritances of CIOMessageMap.
Who can tell me the advantages about this coding style?
There are will best in detail.

Re: Who can explain this code for me?about virtual function by Alex

Alex
Thu Oct 25 01:55:38 PDT 2007

"IOCPer" wrote:
>
> Why class CIOMessageMap should be declared by
> declspec(novtable)?

You don't have to declare it without vtable. The
`__declspec(novtable)' modifier is an optimization. When you
know for sure that some class will never be instantiated,
then you can cancel the generation of [redundant] vtable. It
can reduce the resulting code size.

> The macros implements the member function of
> CIOMessageMap --
> ProcessIOMessage();But in other places of project,there no
> any
> inheritances of CIOMessageMap.

Either you didn't find all occurrences of `CIOMessageMap' or
it's not used anywhere.

> Who can tell me the advantages about this coding style?

The advantage is reduced code size.

> There are will best in detail.

For more details see here:

"novtable"
http://msdn2.microsoft.com/en-us/library/k13k85ky(VS.80).aspx


Alex



Re: Who can explain this code for me?about virtual function by Alexander

Alexander
Thu Oct 25 11:46:39 PDT 2007

The class has a pure virtual method thus it cannot be
instantiated. Hence the __declspec(novtable) optimization.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://vcfaq.mvps.org
=====================================

"IOCPer" <kuibing@gmail.com> wrote in message
news:1193299090.466208.52350@e34g2000pro.googlegroups.com...
> ///////////////////////////////////////////////
> // CIOMessageMap.h
> class __declspec(novtable) CIOMessageMap
> {
> public:
> virtual bool ProcessIOMessage(IOType clientIO, ClientContext*
> pContext, DWORD dwSize) = 0;
> };
>
> #define BEGIN_IO_MSG_MAP() \
> public: \
> bool ProcessIOMessage(IOType clientIO, ClientContext* pContext, DWORD
> dwSize = 0) \
> { \
> bool bRet = false;
>
> #define IO_MESSAGE_HANDLER(msg, func) \
> if (msg == clientIO) \
> bRet = func(pContext, dwSize);
>
> #define END_IO_MSG_MAP() \
> return bRet; \
> }
>
>
> Why class CIOMessageMap should be declared by declspec(novtable)?
> The macros implements the member function of CIOMessageMap --
> ProcessIOMessage();But in other places of project,there no any
> inheritances of CIOMessageMap.
> Who can tell me the advantages about this coding style?
> There are will best in detail.
>