×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

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.