a1193561652 于 2015.05.29 16:55 提问

C++数据结构与算发线性表List问题。

AList.h

`````` #include <list>
template < class Elem >
class AList : public List<Elem>
{
private:
int maxSize;
int listSize;
int fence;
Elem* listArray;
public:
AList(int size=DefaultListSize)
{
maxSize = size;
listSize = fence = 0;
listArrary = new Elem[maxSize];
}
~AList(void)
{
delete [] listArrary;
}
void clear()
{
delete [] listArrary;
listArrary = fence = 0;
listArrary = new Elem[maxSize];
}
bool insert(const Elem&);
bool append(const Elem&);
bool remove(Elem&);
void setStart()
{
fence = 0;
}
void setEnd()
{
fence = listSize;
}
void prev()
{
if(fence != 0)
fence--;
}
void next()
{
if(fence <= listSize)
fence++;
}
int liftLength() const
{
return fence;
}
int right() const
{
return listSize - fence;
}
bool setPos(int Pos)
{
if((Pos >= 0) && (Pos <= listSize))
fence = pos;
return (pos >= 0) && (pos <= listSize)
}
bool getValue(Elem& it) const
{
if(rightLength() == 0)
return false;
else
{
it = listArrary[fence];
return true;
}
}
void print() const
{
int temp = 0;
cout<<"< ";
while(temp < fence)
cout<<listArrary[temp++]<<" ";
cout<<"| ";
while(temp < listSize)
cout<<">\n"
}
};

``````

AList.cpp

`````` #include "AList.h"
template <class Elem>
bool AList<Elem>::insert(const Elem& item)
{
if(listSize == maxSize)
return false;
for(int i=listSize;i>fence;i++)
listArrary[i] = listArrary[i-1];
listArrary[fence] = item;
listSize++;
return true;
}
template <class Elem>
bool AList<Elem>::append(const Elem& item)
{
if(listSize == maxSize)
return false;
listArrary[listSize++] = item;
return true;
}
template <class Elem>
bool AList<Elem>::remove(Elem& it)
{
if(rightLength() == 0)
return false;
it = listArrary[fence];
for(int i=fence;i < listSize-1;i++)
listArrary[i] = listArrary[i+1];
listSize--;
return true;
}

``````

7个回答

u013480667   2015.05.29 20:59

#include

using namespace std; //加上这句

template < class Elem >
class AList : public list

#include
template < class Elem >
class AList : public std::list //改成这样

a1193561652 感谢，确实是这样。

devmiao      2015.05.29 17:13
`````` class AList : public List<Elem>
->
class AList : public list<Elem>
``````
devmiao 回复纵横车: 就改了这一处就可以了。VC6测试通过

a1193561652 改了小写还是同样的错误，刚刚翻书上看是用的大写。

devmiao      2015.05.29 17:50

Tiger_Zhao   2015.05.29 17:01

.h 文件开头加上下面这句，防止重复包含。

``````    #pragma once
``````
a1193561652 是有这句的，我没复制而已。

gamefinity   2015.05.29 17:10

list,l是小写的吧?

gamefinity 回复纵横车: 翻书没有用。看MSDN才是正确的。仍然报的错还是那个么？

a1193561652 改了小写还是同样的错误，刚刚翻书上看是用的大写。

nswcfd   2015.05.29 19:55

nswcfd 尖括号的内容都被吞掉了……

dominating413421391   2015.06.07 00:10