Polymorphic objects on the stack?

后端 未结 7 676
忘了有多久
忘了有多久 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:23

    I think the point is that this is not "really" polymorphic (whatever that means :-).

    You could write your test function like this

    template
    void test(T& obj)
    {
        obj.f();
    }
    

    and it would still work, whether the classes have virtual functions or not.

提交回复
热议问题