/
rokhin
/
Small_test_programs_cpp
Обзор
Документация
Войти
/
rokhin
/
Small_test_programs_cpp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
virtual.cpp
35 строк
603 B
sergeyrokhin
Начало
03 фев 2025, 13:36
03 фев 2025, 13:36
e354b68
Код
Авторство
О чём код?
#include <iostream> struct X { virtual void f() const { std::cout << "X"; } X& operator=(const X& other) { memcpy(this, &other, sizeof(other)); return *this; } X& operator=(X& other) { memcpy(this, &other, sizeof(other)); return *this; } }; struct Y : public X { virtual void f() const override { std::cout << "Y"; } }; void print(const X &x) { x.f(); } int main(int argc, char const *argv[]) { X arr[1]; Y y1; X x1; x1 = y1; arr[0] = y1; print(y1); print(arr[0]); arr[0].f(); x1.f(); return 0; }