Can we have a virtual static method ? (c++) [duplicate]

偶尔善良 提交于 2019-12-03 22:02:48

No. static on a function in a class means that the function doesn't need an object to operate on. virtual means the implementation depends on the type of the calling object. For static there is no calling object, so it doesn't make sense to have both static and virtual on the same function .

Don't think this is possible because you could call A::F(); without having the object A. Making it virtual and static would mean a contradiction.

Because the class doesn't have a this pointer. In there is the virtual function lookup table. A quick google can tell you more about the virtual function lookup table.

No, static function is like global function, but also inside class namespace. virtual implies inheritance and reimplementing in derived class - you can't reimplement 'global' function.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!