static_cast to dynamic_cast

This commit is contained in:
gandc committed 2024-05-23 02:19:07 +03:00
1 parent f2e2c80652
commit d265b73748
1 file changed
+5 -1
+5 -1
View File
@@ -35,6 +35,8 @@ public:
next = nextElement; next = nextElement;
} }
virtual ~Element() {}
template<class T1> friend class LinkedList; template<class T1> friend class LinkedList;
template<class T1> friend class DoublyLinkedStack; template<class T1> friend class DoublyLinkedStack;
template<class T1> friend ostream& operator<<(ostream& s, const Element<T1>& el); template<class T1> friend ostream& operator<<(ostream& s, const Element<T1>& el);
@@ -216,7 +218,9 @@ public:
if (this->tail == nullptr) if (this->tail == nullptr)
return 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) { if (this->head == this->tail) {
this->head = this->tail = nullptr; this->head = this->tail = nullptr;