Polymorphic objects on the stack?

后端 未结 7 670
忘了有多久
忘了有多久 2021-02-01 02:53

In Why is there no base class in C++?, I quoted Stroustrup on why a common Object class for all classes is problematic in c++. In that quote there is the statement:

相关标签:
7条回答
  • 2021-02-01 03:47

    Looks like polymorphism to me.

    Polymorphism in C++ works when you have indirection; that is, either a pointer-to-T or a reference-to-T. Where T is stored is completely irrelevant.

    Bjarne also makes the mistake of saying "heap-allocated" which is technically inaccurate.

    (Note: this doesn't mean that a universal base class is "good"!)

    0 讨论(0)
提交回复
热议问题