How to enforce a static member on derived classes?

后端 未结 4 1649
终归单人心
终归单人心 2021-01-12 22:31

I have a base class, Primitive, from which I derive several other classes--Sphere, Plane, etc.

Primitive enforces

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-12 23:15

    For the reasons they discussed in the link you provided, you cannot make a virtual member static.

    Your question about the requirement of enforcing the function on derived classes is handled by making the function pure virtual in the abstract base class which will enforce that derived classes must implement the function.

提交回复
热议问题