私は帰国している大学生です。私のコードはその年以来本当に錆びています。彼は私たちにUMLテンプレートを与えたプログラムを持っています。とにかく私はコンパイル時に問題を見つけることができません、私はc2259エラーを取得し、抽象クラスをインスタンス化することはできません。何か案は?C++抽象クラスエラーをインスタンス化できません
#ifndef OLISTTYPE_H
#define OLISTTYPE_H
#include "ListType.h"
template <class T>
class OListType: public ListType<T> {
public:
bool insert(const T&);
void insertFirst(const T&);
void insertLast(const T&);
bool find(const T&) const;
};
template <class T>
bool OListType<T>::find(const T& item) const {
NodeType<T>* temp = this->head;
while (temp != NULL && temp->info < item) {
temp = temp->link;
}
return(temp != NULL && temp->info == item);
}
template <class T>
bool OListType<T>::insert(const T& newItem) {
NodeType<T> *current;
NodeType<T> *trailCurrent;
NodeType<T> *newNode;
bool found;
newNode = new NodeType<T>;
newNode->info = newItem;
newNode->link = nullptr;
if (first == nullptr) {
first = newNode;
last = newNode;
count++;
}
else {
current = first;
found = false;
while (current != nullptr && !found)
if (current->info >= newItem)
found = true;
else {
trailCurrent = current;
current = current->link;
}
if (current == first) {
newNode->link = first;
first = newNode;
count++;
}
else {
trailCurrent->link = newNode;
newNode->link = current;
if (current == nullptr)
last = newNode;
count++;
}
}
}
template<class T>
void OListType<T>::insertFirst(const T& newItem) {
insert(newItem);
}
template<class T>
void OListType<T>::insertLast(const T& newItem) {
insert(newItem);
}
#endif
はListType.h
コンパイラは、このエラーを与える
#ifndef LISTTYPE__H
#define LISTTYPE__H
#include <cstddef>
#include "Nodetype.h"
#include <iostream>
template <class T>
class ListType {
public:
ListType();
ListType(const ListType<T>&);
virtual ~ListType();
bool operator=(const ListType<T>& right) const;
virtual bool insert(const T&) = 0;
virtual bool eraseAll();
virtual bool erase(const T&) = 0;
bool find(const T&) const;
size_t size() const;
bool empty() const;
friend std::ostream& operator<< (std::ostream&, const ListType&);
protected:
int count;
NodeType<T> *first;
NodeType<T> *last;
private:
void destroy();
void copy(const ListType<T>&);
};
template <class T>
ListType<T>::ListType()
{
first = nullptr;
last = nullptr;
count = 0;
}
template <class T>
ListType<T>::ListType(const ListType<T>& otherList) {
first = nullptr;
copyList(otherList);
}
template <class T>
ListType<T>::~ListType() {
destroy();
}
template<class T>
bool ListType<T>::operator=(const ListType<T>& right) const
{
return (current = right.current);
}
template <class T>
bool ListType<T>::eraseAll() {
head = 0;
return true;
}
template <class T>
bool ListType<T>::erase(const T& it) {
if (head == 0)
{
return false;
}
else
{
struct NodeType<T> *u = head->next, *p = head;
if (head->item == it)
{
head = head->next;
return true;
}
while (u != 0 && u->next != 0)
{
if (u->item == it)
{
p->next = u->next;
return true;
}
u = u->next;
p = p->next;
}
if (u->next == 0 && u->item == it)
{
p->next = 0;
return true;
}
return false;
}
}
template <class T>
bool ListType<T>::find(const T& it) const {
if (head == 0)
{
return false;
}
else
{
struct NodeType<T> *p = head;
while (p->next != 0)
{
if (p->item == it)
{
return true;
}
p = p->next;
}
return false;
}
}
template <class T>
size_t ListType<T>::size() const {
return count;
}
template <class T>
bool ListType<T>::empty() const
{
return (first == nullptr);
}
template <class T>
void ListType<T>::destroy() {
NodeType<T> *temp;
while (first != nullptr)
{
temp = first;
first = first->link;
delete temp;
}
last = nullptr;
count = 0;
}
template <class T>
void ListType<T>::copy(const ListType<T>& otherList) {
nodeType<Type> *newNode;
nodeType<Type> *current;
if (first != nullptr)
destroylist();
if (otherList.first = nullptr)
{
first = nullptr;
last = nullptr;
count = 0;
}
else {
current = otherList.first;
count = otherList.count;
first = new NodeType<T>;
first->info = current->info;
first->link = nullptr
last = first;
current = current->link;
while (current != nullptr) {
newNode = new NodeType<Type>;
newNode->info = current->info;
newNode->link = nullptr;
last->link = newNode;
last = newNode;
current = current->link;
}
}
}
template <class T>
std::ostream &operator<< (std::ostream &out, const ListType<T> &list) {
if (list.head) {
NodeType<T> *temp = list.head;
out << list.head->item;
temp = temp->next;
while (temp != 0) {
out << "," << temp->item;
temp = temp->next;
}
}
return out;
}
#endif
'OListType'は純粋仮想関数' erase() 'をオーバーライドできません。このテンプレートは、あなたが知っているようにインスタンス化できない抽象クラスを宣言することにもなります。あなたの質問は何ですか? –
あなたの元の大学時代には空白と書式がありました:) – jww