Generating an interface without virtual functions?

后端 未结 3 1034
迷失自我
迷失自我 2020-11-28 14:13

I\'m coding a game engine and I have this class set up for objects:

class SceneManager //controls everything in the \"world\" game
{
    public:
        void         


        
3条回答
  •  感情败类
    2020-11-28 14:42

    Solving your specific petition is one thing that others have already done.

    However, I think you should take a step back and consider the whole picture. Is this a wise step to take? Any possible alternative to virtual functions will introduce maintainability problems, i.e., difficulty to modify and even to understand code.

    The question is: is this really necessary? Will it really compensate?

    Virtual functions involve derreferencing two pointers instead of only one. And yes, it is true it won't be inlined. I don't think, however, this being a real issue. I would indeed concentrate in algorithm-level optimization, and waste all other approaches before removing virtual funcions.

    Take into account that at least one solution involves converting virtual functions to regular functions (not member functions), removing the well-known advantage of a virtual function (i.e., the class of the object itself) vs. a chain of if's.

    That's said, it is your call.

提交回复
热议问题