Linux 下C++编译异常,哪位帮小弟我搞下,多谢了
Linux 下C++编译错误,哪位帮我搞下,谢谢了
我想实现一个模板,是一个顺序链表
一些功能还没有完成,但是编译应该不会有问题的
代码如下,
---------Sqlist.h
#ifndef SQLIST_H
#define SQLIST_H
//顺序结构
const int MAXLEN=200;
template <typename type>
class Sqlist
{
public:
Sqlist(const type* a, const int size);
public:
void Clear();
bool isEmpty();
int getLength(){return length;}
type& getItem(int i);
type& prior(const int pos);
type& next(const int pos);
int find(const type x);
Sqlist <type> &
insert(int pos,type x);
Sqlist <type> &
remove(int pos);
void print();
private:
type* data;
int length;
};
#endif
------Sqlist.cc
#include "Sqlist.h "
#include <iostream>
using namespace std;
template <typename type>
Sqlist <type> ::Sqlist(const type* a, const int size)
{
if(a)
{
if(size <=0&&size> MAXLEN)
{
cout < < "Create Error.\n ";
exit(1);
}
else
{
length=size;
data=new type[size];
for(int i=0; i <size; i++ )
data[i]=a[i];
}
}
}
template <typename type>
void Sqlist <type> ::Clear()
{
if(!isEmpty())
delete [] data;
cout < < "Clear Error. ";
}
template <typename type>
bool isEmpty()
{
if(length==0)
return true;
else
return false;
}
template <typename type>
type& Sqlist <type> ::getItem(int i)
{
if(data&&(i <length)&&(i> 0))
return data[i];
}
template <typename type>
int Sqlist <type> ::find(const type x)
{
for(int i=0; i <length; i++)
if(data[i]==x)
return i;
return -1;
}
template <typename type>
type& Sqlist <type> ::prior(const int pos)
{
if(pos=0)
{
cout < < "The first element has no prior elem.\n ";
exit(1);
}
else if(pos> 0&&data&&pos <length)
return data[pos-1];
}
template <typename type>
我想实现一个模板,是一个顺序链表
一些功能还没有完成,但是编译应该不会有问题的
代码如下,
---------Sqlist.h
#ifndef SQLIST_H
#define SQLIST_H
//顺序结构
const int MAXLEN=200;
template <typename type>
class Sqlist
{
public:
Sqlist(const type* a, const int size);
public:
void Clear();
bool isEmpty();
int getLength(){return length;}
type& getItem(int i);
type& prior(const int pos);
type& next(const int pos);
int find(const type x);
Sqlist <type> &
insert(int pos,type x);
Sqlist <type> &
remove(int pos);
void print();
private:
type* data;
int length;
};
#endif
------Sqlist.cc
#include "Sqlist.h "
#include <iostream>
using namespace std;
template <typename type>
Sqlist <type> ::Sqlist(const type* a, const int size)
{
if(a)
{
if(size <=0&&size> MAXLEN)
{
cout < < "Create Error.\n ";
exit(1);
}
else
{
length=size;
data=new type[size];
for(int i=0; i <size; i++ )
data[i]=a[i];
}
}
}
template <typename type>
void Sqlist <type> ::Clear()
{
if(!isEmpty())
delete [] data;
cout < < "Clear Error. ";
}
template <typename type>
bool isEmpty()
{
if(length==0)
return true;
else
return false;
}
template <typename type>
type& Sqlist <type> ::getItem(int i)
{
if(data&&(i <length)&&(i> 0))
return data[i];
}
template <typename type>
int Sqlist <type> ::find(const type x)
{
for(int i=0; i <length; i++)
if(data[i]==x)
return i;
return -1;
}
template <typename type>
type& Sqlist <type> ::prior(const int pos)
{
if(pos=0)
{
cout < < "The first element has no prior elem.\n ";
exit(1);
}
else if(pos> 0&&data&&pos <length)
return data[pos-1];
}
template <typename type>