static_cast to dynamic_cast

This commit is contained in:
gandc 2024-05-23 02:19:07 +03:00
parent f2e2c80652
commit d265b73748
Signed by: gandc
GPG Key ID: 9F77B03D43C42CB4

View File

@ -35,6 +35,8 @@ public:
next = nextElement;
}
virtual ~Element() {}
template<class T1> friend class LinkedList;
template<class T1> friend class DoublyLinkedStack;
template<class T1> friend ostream& operator<<(ostream& s, const Element<T1>& el);
@ -216,7 +218,9 @@ public:
if (this->tail == nullptr)
return nullptr;
DoublyLinkedElement<T>* res = static_cast<DoublyLinkedElement<T>*>(this->tail);
//DoublyLinkedElement<T>* res = static_cast<DoublyLinkedElement<T>*>(this->tail);
// Преобразование указателя на базовый класс в указатель на производный класс
DoublyLinkedElement<T>* res = dynamic_cast<DoublyLinkedElement<T>*>(this->tail);
if (this->head == this->tail) {
this->head = this->tail = nullptr;