static_cast to dynamic_cast
This commit is contained in:
1 file changed
+5
-1
@@ -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;
|
||||||
|
|||||||
Reference in new issue
Block a user