×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

implementation

this implementation is easy to find if you are on Windows. [COM related] when you compile myfile.idl by MIDL compiler, a new file myfile.h will be generated. this file has implementation of C style virtual function. For exaple,
//myfile.h
typedef struct Iaa1Vtbl
{
long ( *AddRef )( Iaa1 * This);
} Iaa1Vtbl;
struct Iaa1{ struct Iaa1Vtbl *lpVtbl;};

long AddRef(){ cout<<"do nothing"<<endl; return 12345;}
[code presented without test]

as I know, virtual function is in scope of C++, it is used for Inheretance and Polymophism, so why you need them in C. you are doing the work of C++ compiler.
Report

Replies, comments and Discussions:

  • 工作学习 / IT杂谈 / 请教一个问题:怎样用C去实现virtual function.
    • implementation
      this implementation is easy to find if you are on Windows. [COM related] when you compile myfile.idl by MIDL compiler, a new file myfile.h will be generated. this file has implementation of C style virtual function. For exaple,
      //myfile.h
      typedef struct Iaa1Vtbl
      {
      long ( *AddRef )( Iaa1 * This);
      } Iaa1Vtbl;
      struct Iaa1{ struct Iaa1Vtbl *lpVtbl;};

      long AddRef(){ cout<<"do nothing"<<endl; return 12345;}
      [code presented without test]

      as I know, virtual function is in scope of C++, it is used for Inheretance and Polymophism, so why you need them in C. you are doing the work of C++ compiler.