Информация об изменениях

Сообщение Re: Изменение сигнатуры виртуальной функции от 18.04.2023 15:02

Изменено 18.04.2023 15:03 rg45

Re: Изменение сигнатуры виртуальной функции
Здравствуйте, Muxa, Вы писали:

M>Почему компилятор такое позволяет для F0 и F1, но не позволяет для F2 и F3?


Относительно F0 и F1 в стандарте языка есть ясное правило, разрешающее ковариантрость возвращаемых типов:

https://timsong-cpp.github.io/cppwp/class.virtual#8

The return type of an overriding function shall be either identical to the return type of the overridden function or covariant with the classes of the functions.
If a function D​::​f overrides a function B​::​f, the return types of the functions are covariant if they satisfy the following criteria:
    - both are pointers to classes, both are lvalue references to classes, or both are rvalue references to classes102
    - the class in the return type of B​::​f is the same class as the class in the return type of D​::​f, or is an unambiguous and accessible direct or indirect base class of the class in the return type of D​::​f
    - both pointers or references have the same cv-qualification and the class type in the return type of D​::​f has the same cv-qualification as or less cv-qualification than the class type in the return type of B​::​f.


Почему сделано так или иначе объяснения, данные здесь
Автор: Coreman
Дата: 18.04.23
и здесь
Автор: Zhendos
Дата: 18.04.23
, на мой взгляд, выглядят вполне разумными.
Re: Изменение сигнатуры виртуальной функции
Здравствуйте, Muxa, Вы писали:

M>Почему компилятор такое позволяет для F0 и F1, но не позволяет для F2 и F3?


Относительно F0 и F1 в стандарте языка есть ясное правило, разрешающее ковариантрость возвращаемых типов:

https://timsong-cpp.github.io/cppwp/class.virtual#8

The return type of an overriding function shall be either identical to the return type of the overridden function or covariant with the classes of the functions.
If a function D​::​f overrides a function B​::​f, the return types of the functions are covariant if they satisfy the following criteria:
    - both are pointers to classes, both are lvalue references to classes, or both are rvalue references to classes102
    - the class in the return type of B​::​f is the same class as the class in the return type of D​::​f, or is an unambiguous and accessible direct or indirect base class of the class in the return type of D​::​f
    - both pointers or references have the same cv-qualification and the class type in the return type of D​::​f has the same cv-qualification as or less cv-qualification than the class type in the return type of B​::​f.


Почему сделано так а не иначе, объяснения, данные здесь
Автор: Coreman
Дата: 18.04.23
и здесь
Автор: Zhendos
Дата: 18.04.23
, на мой взгляд, выглядят вполне разумными.