主题:头文件加主函数的编译,帮帮忙!
一湾浅水
[专家分:230] 发布于 2008-09-28 01:28:00
弄明白了……原来有个东西叫工程,晕死……
[b]头文件、函数之间的连接老师根本没讲,就叫我们做数据结构……[/b]
--------------------配置: mingw2.95 - CUI Debug, 编译器类型: MinGW (Old)-------------
-------
检查文件依赖性...
正在连接...
[Error] D:\My Documents\数据结构\SqList\list.cpp:6: undefined reference to `SqList::SqList(void)'
[Error] D:\My Documents\数据结构\SqList\list.cpp:6: undefined reference to `SqList::~SqList(void)'
[Error] D:\My Documents\数据结构\SqList\list.cpp:7: undefined reference to `SqList::isFull(void) const'
[Error] D:\My Documents\数据结构\SqList\list.cpp:11: undefined reference to `SqList::~SqList(void)'
构建中止 list: 4 个错误, 0 个警告
[em10]
最后更新于:2008-09-28 04:47:00
回复列表 (共3个回复)
沙发
一湾浅水 [专家分:230] 发布于 2008-09-28 01:29:00
// SqList.h--class definition for the SqList ADT
#ifndef SqList_H
#define SqList_H
typedef int ElemType;
class SqList
{
private:
static const int init_size = 100;
static const int increment_size = 10;
ElemType *elem;
int length; //当前长度
int size; //当前分配的存储容量
public:
SqList();
~SqList();
bool isEmpty()const;
bool isFull()const;
/*
int findLength()const;
*/
int locateElem (const ElemType &e)const;
int priorElem (const ElemType &e)const;
int nextElem (const ElemType &e)const;
bool listInsert (int po, const ElemType &e);
bool listDelete (int po, ElemType &e);
};
#endif SqList_H
板凳
一湾浅水 [专家分:230] 发布于 2008-09-28 01:29:00
//SqList.cpp--SqList member functions
#include <iostream>
#include "SqList.h"
SqList::SqList()
{
elem = new ElemType [init_size]; // 当前空间基址
length = 0; // 当前长度
size = init_size; //当前分配的存储容量
}
SqList::~SqList()
{
delete [] elem;
}
bool SqList::isEmpty()const
{
return length == 0;
}
bool SqList::isFull()const
{
return length == init_size ;
}
/*
int SqList::findLength()const
{
int temp = length;
return temp;
}
*/
//元素位序
int SqList::locateElem (const ElemType &e)const
{
for (int i = 0; i < length; ++i)
{
if (elem[i] == e)
{
return i+1;
break;
}
}
return 0;
}
// 元素前驱位序
int SqList::priorElem (const ElemType &e)const
{
for (int i = 0; i < length; ++i)
{
if (elem[i] == e)
{
return i;
break;
}
}
return -1;
}
// 元素后继位序
int SqList::nextElem (const ElemType &e)const
{
for (int i = 0; i < length; ++i)
{
if (elem[i] == e)
{
return i+2;
break;
}
}
return -1;
}
bool SqList::listInsert (int po, const ElemType &e)
{
if ( !isFull() )
{
if ( 1 <= po && po <= init_size )
{
for (int i = length; i >= po; --i)
{
elem[i] = elem[i-1];
}
elem[po-1] = e;
++length;
return true;
}
}
return false;
}
bool SqList::listDelete (int po, ElemType &e)
{
if ( !isEmpty() )
{
if ( 1 <= po && po <= init_size )
{
e = elem[po-1];
for (int i = po; i <= length; ++i)
{
elem[i-1] = elem[i];
}
--length;
return true;
}
}
return false;
}
3 楼
一湾浅水 [专家分:230] 发布于 2008-09-28 01:30:00
//list.cpp--testing the SqList class
#include <iostream>
#include "SqList.h"
int main()
{
SqList one;
if ( one.isFull() )
{
std::cout << "good" << endl;
}
return 0;
}
我来回复