Can you cache a virtual function lookup in C++?

前端 未结 9 1145
故里飘歌
故里飘歌 2021-01-31 15:39

Say I have a virtual function call foo() on an abstract base class pointer, mypointer->foo(). When my app starts up, based on the contents of a file, it chooses to instantiate a

9条回答
  •  情深已故
    2021-01-31 16:08

    Could you use a method pointer?

    The objective here is that the compiler would load the pointer with the location of the resolved method or function. This would occur once. After the assignment, the code would access the method in a more direct fashion.

    I know that a pointer to an object and accessing the method via the object point invokes run-time polymorphism. However, there should be a way to load a method pointer to a resolved method, avoiding the polymorphism and directly calling the function.

    I've checked the community wiki to introduce more discussion.

提交回复
热议问题