我写了一个类来帮助学习数据结构。我以前成功使用过这种方法,但这次不喜欢return new linkedlist();
在文件Factory.cpp中
#include "list.h"
using namespace std;
LinkedListInterface * Factory::getLinkedList
{
return new linkedlist();
}
在文件Factory.h
#pragma once
#include "LinkedListInterface.h"
using namespace std;
class Factory
{
public:
static LinkedListInterface * getLinked();
};
文件list.h,我在其中有一个基本构造函数,该类称为linkedlist
#include using namespace std;
class linkedlist
{
private:
typedef struct node
{
int data;
node* next;
}* nodePtr;
nodePtr head;
nodePtr curr;
nodePtr temp;
public:
linkedlist()
{
head = NULL;
curr = NULL;
temp = NULL;
}
......
};
there are other functions but i dont think they causing my problem.
这是来自我教授的 LinkeListInterface.h。文件的其余部分是虚拟方法,我确保将它们包含在 list.h #pragma once #include
using namespace std;
class LinkedListInterface
{
public:
LinkedListInterface(void){};
virtual ~LinkedListInterface(void){};