연결 목록을 구현하는 대기열을 만들려고하지만 컴파일러 오류가 발생합니다. 오류는 소멸자 (모든 대문자 주석으로 표시)를 호출하는 행에서 오버로드 된 대입 연산자 함수에서 발생합니다. 나는 그것이 내 생성자/소멸자 선언의 구문과 관련이있는 간단한 수정 인 직감이있다.생성자 및 소멸자 선언 구문 템플릿 클래스
오류 것은 내가 국가에게 다음 코드를 얻고있다 : error C2512: 'Queue<char>::Queue' : no appropriate default constructor available
그것은 생성자를 언급,하지만 라인이가 의미하는 것은 내가 소멸자를 호출하려고 경우 아래의 하나입니다.
미리 도움을 주셔서 감사합니다.
#ifndef QUEUE_H
#define QUEUE_H
#include <iostream>
using namespace std;
template <class Type>
class Queue // Create a Queue data structure implementing a linked list
{
private: // The private members
struct Cell // The Cell class will be the blueprints for each link in the list
{
Type data; // The information held by the cell
Cell* next; // The link to the next cell
};
Cell* first = NULL;
Cell* last = NULL;
public: // The public members
Queue(Type);
bool isEmpty();
void push(Type);
Type pop();
Queue<Type>& operator=(Queue<Type>&);
friend ostream& operator<<(ostream&, const Queue<Type>&);
~Queue();
};
template<class Type>
Queue<Type>::Queue(Type inputData) // Constructor that initializes the queue with a new cell that last and first point to
{
first = new Cell;
first->data = inputData;
first->next = NULL;
last = first;
}
template<class Type>
Queue<Type>& Queue<Type>::operator=(Queue<Type>& queue) // Overload "=" so that it performs a deep copy of a Queue object
{
if (!queue.isEmpty())
{
~Queue(); // HERE IS THE ERROR LINE
Cell* rhs = queue.first;
while (rhs != NULL)
{
push(rhs->data);
rhs = rhs->next;
}
}
return *this;
}
template<class Type>
Queue<Type>::~Queue() // Destructor that deallocates all of the memory used by the queue.
{
if (!isEmpty()) // We only need to deallocate the queue if it is non-empty
{
Cell *link = last;
while (link != NULL) // Until we reach the end of the queue, keep deleting each link
{
pop();
}
first = NULL;
last = NULL;
}
else // If the queue is already empty, let the user know
{
cout << "Cannot call destructor. The list is already empty.\n";
}
}
#endif
이것은 도움이되었습니다, 감사합니다. 나는 지금 어떤 종류의 "해결되지 않은 외부 기호"로 오류를 얻고있다. 블레 – Peter