“As a rule of thumb, make all your methods virtual” in C++ - sound advice?

前端 未结 5 1022
野性不改
野性不改 2021-01-07 23:38

I just happened upon the statement in the title. The full quote is:

As a rule of thumb, make all your methods virtual (including the destructor, but

5条回答
  •  情深已故
    2021-01-08 00:13

    There will be a tiny loss in performance and a few bytes of memory wasted.

    The real problem is that it makes the code less maintainable because you are saying something about the function that isn't true. It could cause a lot of confusion.

提交回复
热议问题