C ++中的根类 [英] Root base class in C++
问题描述
.NET中的每个对象都从公共根基Object继承(直接或间接)。在C ++中有这样一个共同的对象根?如何将任何对象传递给函数?
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 a function?
public void DoSomeStuff(object o) { ... }
编辑:澄清,目的:在该函数中,我要调用一个指针成员函数。为此,我需要对象实例和指针所需的函数。为了简化可读性,我想创建一个包含所需信息的包装器。
To clarify, the purpose: In that function I want to invoke a pointer to member function. For that I need the object instance and pointer to the required function. To simplify readability I want to make a wrapper containing the both required information. I'm not sure if that is the best way, but it is the background idea.
推荐答案
没有普通的根类,我不知道这是否是最好的方法, 。使用void *将任何对象传递给函数,或者更好地定义一些基类。
There is no common root class. Use either void* to pass any object into a function, or better define some base class.
这篇关于C ++中的根类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!