#include <iostream> using namespace std; class Base { public: virtual void show() { cout << "Base class\n"; } }; class Derived : public Base { public: void show() override { cout << "Derived class\n"; } }; int main() { Base* basePtr = new Derived(); Derived* derivedPtr = dynamic_cast<Derived*>(basePtr); // استفاده از dynamic_cast if (derivedPtr) { derivedPtr->show(); // خروجی: Derived class } else { cout << "Conversion failed\n"; } return 0; }