Root base class in C++

前端 未结 7 1474
逝去的感伤
逝去的感伤 2021-01-04 11:29

Every object in .NET inherits (directly or indirectly) from the common root base \"Object\". Is there such a common object root in C++? How do I pass any object to

7条回答
  •  一生所求
    2021-01-04 12:08

    For that I need the object instance and pointer to the required function.

    That sounds a lot like "delegates". First, you definitely will need to define a common base class for all the objects that you want to call. In C++ you can use multiple inheritance if the object already belong to some other hierarchy.

    Then have a read through Member Functions and the Fastest Possible C++ Delegates which is an excellent in-depth article on the topic of delegates (which are an object and member function pointer bound together). Using the header file described in that article, you can create delegates and easily call them just like regular function pointers.

提交回复
热议问题