A virtual member function is used if it is not pure?

前端 未结 5 2291
长情又很酷
长情又很酷 2021-02-15 12:03

C++03 3.2.2 ...An object or non-overloaded function is used if its name appears in a potentially-evaluated expression. A virtual member function is used

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-15 12:34

    This code violates ODR. A::f is multiply defined. Hence it has UB.

    Multiple definitions across translation units are only allowed for the following as per $3.2/5

    There can be more than one definition of a class type (clause 9), enumeration type (7.2), inline function with external linkage (7.1.2), class template (clause 14), non-static function template (14.5.5), static data member of a class template (14.5.1.3), member function of a class template (14.5.1.1), or template specialization for which some template parameters are not specified (14.7, 14.5.4) in a program provided that each definition appears in a different translation unit, and provided the definitions satisfy the following requirements.

提交回复
热议问题