且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C ++静态虚拟成员?

更新时间:2021-08-10 01:12:54

没有办法做,因为当你调用 Object :: GetTypeInformation()会发生什么?它不能知道要调用哪个派生类版本,因为没有与它相关联的对象。

No, there's no way to do it, since what would happen when you called Object::GetTypeInformation()? It can't know which derived class version to call since there's no object associated with it.

您必须将其作为非静态虚函数才能正常工作;如果你还想要在没有对象实例的情况下非虚拟地调用一个特定的派生类的版本,你必须提供第二个redunduant静态非虚拟版本。

You'll have to make it a non-static virtual function to work properly; if you also want to be able to call a specific derived class's version non-virtually without an object instance, you'll have to provide a second redunduant static non-virtual version as well.