The rationale that you included is reasonably clear: naturally, virtual functions are meant to be overridden by subclasses, so you as the designer of the base class should make it as easy as possible for people who inherit your class to provide a suitable override. However, if you use auto
, figuring out the return type for the override becomes a tedious task for a programmer. Compilers would have less of a problem with it, but humans would have many opportunities to get confused.
For example, if you see a return statement that looks like this
return a * 3 + b;
you would have to trace the program back to the point of declaration of a
and b
, figure out the type promotions, and decide what the return type shall be.
It appears that the language designers figured out that this would be rather confusing, and decided against allowing this feature.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…