Virtual Methods or Function Pointers

后端 未结 8 1454
春和景丽
春和景丽 2020-12-07 11:31

When implementing polymorphic behavior in C++ one can either use a pure virtual method or one can use function pointers (or functors). For example an asynchronous callback c

8条回答
  •  借酒劲吻你
    2020-12-07 12:23

    One major advantage of the first method is it has more type safety. The second method uses a void * for iParam so the compiler will not be able to diagnose type problems.

    A minor advantage of the second method is that it would be less work to integrate with C. But if you're code base is only C++, this advantage is moot.

提交回复
热议问题