static_cast to dynamic_cast
This commit is contained in:
6
pr6.cpp
6
pr6.cpp
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user