type-narrowing

Narrowing Conversion required while list initialization

旧巷老猫 提交于 2019-12-10 20:39:41
问题 I read about narrowing conversion on the cpp reference website. I kind of understood it but what i am not getting is that why is the error present only in the first line. long double ld = 3.1415926536; int a{ld}, b = {ld}; // error: narrowing conversion required int c(ld), d = ld; // ok: but value will be truncated Why is the error only present in first line and not the second? 回答1: Because the compiler is required to issue a diagnostic (in your case error) for narrowing only for list

Narrowing return type on inheritance for abstract method through PHPdoc causes PHP error

巧了我就是萌 提交于 2019-12-04 05:07:09
问题 Assume we have the following inheritance chain in PHP abstract class Entity {} abstract class RealEntity extends Entity {} abstract class PseudoEntity extends Entity {} and a bunch of other classes that mirror the same inheritance chain abstract class EntitySerializer { /** * @return Entity */ abstract public function getEntity(); } abstract class RealEntitySerializer extends EntitySerializer { /** * @return RealEntity */ abstract public function getEntity(); } abstract class