Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Who can explain this code for me?about virtual function

Who can explain this code for me?about virtual function

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kuibing
    wrote on last edited by
    #1

    /////////////////////////////////////////////// // 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.;)

    M 1 Reply Last reply
    0
    • K kuibing

      /////////////////////////////////////////////// // 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.;)

      M Offline
      M Offline
      mid 5741
      wrote on last edited by
      #2

      ProcessIOMessage() is defined as virtual, so the compiler wants to add a vtable for the class. But, because it's an abstract class (due to the = 0) it cannot be instantiated and doesn't need the overhead of the vtable. __declspec(novtable) instructs the compiler to not generate a vtable. A more detailed explanation can be found here[^].

      Cyril Connolly wrote:

      Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups