C++ Class Extension

前端 未结 9 1204
既然无缘
既然无缘 2020-12-11 03:22

Is there a way to add new methods to a class, without modifying original class definition (i.e. compiled .lib containing class and corresponding .h file) like C#\'s class ex

9条回答
  •  执念已碎
    2020-12-11 03:41

    No. C++ has no such capability.

    As mentioned in other answers, the common workarounds are:

    • Define a derived class, perhaps with a factory to hide the actual implementation class
    • Define a decorator class
    • Define non-member functions that operate on instances of the class

提交回复
热议问题