| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 609 人关注过本帖
标题:求助,数组实现的线性表编译错误
只看楼主 加入收藏
sophia
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2004-9-5
收藏
 问题点数:0 回复次数:3 
求助,数组实现的线性表编译错误

哪位高人帮我看下下面的代码为什么链接出错!

分三个文件,在main中用 ArrayList<int> intArrayList(5); 定义一个对像就出错,但ArrayList<int> intArrayList();可以通过。

/* 文件名:ArrayList.cpp
*
* 功能:
*
* 作者:
* 时间:
*
* 描述:
*/
#include <iostream>
#include "ArrayList.h"

template <class T>
ArrayList<T>::ArrayList(int size)
{
_List = new T [size];
_length = 0;
_size = size;
}


/* 文件名:main.cpp
*
* 功能:
*
* 作者:
* 时间:
*
* 描述:
*/
#include <iostream>
#include "ArrayList.h"

using namespace std;

int main()
{
ArrayList<int> intArrayList(5);
system("PAUSE");
return 0;
}



/* 文件名: ArrayList.h
*
* 功能: 用数组描述的线性类声明
*
* 作者: zhoujun
* 时间: 2006-3-23
*
* 描述: Array_LinearList
*/
#ifndef ArrayList_H_
#define ArrayList_H_
#include <iostream>


template <class T>
class ArrayList
{
public:
ArrayList(int size = 10);
~ArrayList() { delete [] _List;}
bool IsEmpty();
int Length();
bool Find(int k, T& x) const;
int Search(const T& x) const;
ArrayList<T>& Insert(int k, const T& x);
ArrayList<T>& Delete(int k, T& x);
void OutPut(std::ostream& out) const;

private:
int _length;
T * _List;
int _size;
};

#endif


出错信息:
[Linker error] undefined reference to `ArrayList<int>::ArrayList(int)'
ld returned 1 exit status
搜索更多相关主题的帖子: 线性 编译 
2006-03-23 19:38
lizecn
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-3-23
收藏
得分:0 

以下的代码编译通过,没有修改你的代码,估计问题出在makefile
或者头文件宏预处理有问题,可以试一下一个干净的头文件。




#include <iostream>
using namespace std;

template <class T>
class ArrayList
{
public:
ArrayList(int size = 10);
~ArrayList() { delete [] _List;}
bool IsEmpty();
int Length();
bool Find(int k, T& x) const;
int Search(const T& x) const;
ArrayList<T>& Insert(int k, const T& x);
ArrayList<T>& Delete(int k, T& x);
void OutPut(std::ostream& out) const;

private:
int _length;
T * _List;
int _size;
};
template <class T>
ArrayList<T>::ArrayList(int size)
{
_List = new T [size];
_length = 0;
_size = size;
}


int main()
{
ArrayList<int> intArrayList(5);
system("PAUSE");
return 0;
}

2006-03-23 20:44
sophia
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2004-9-5
收藏
得分:0 
谢谢楼上的回复

我在DEV C++ 和 VC6.0下都编译不过
应该是代码哪里有点问题。

继续期待~~~
2006-03-25 12:08
阿甘
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2005-6-9
收藏
得分:0 

/* 文件名:ArrayList.cpp
*
* 功能:
*
* 作者:
* 时间:
*
* 描述:
*/
#include <iostream>
#include "ArrayList.h"

template <class T>
ArrayList<T>::ArrayList(int size)
{
_List = new T [size];
_length = 0;
_size = size;
}


/* 文件名:main.cpp
*
* 功能:
*
* 作者:
* 时间:
*
* 描述:
*/
#include <iostream>
#include"ArrayList.h" #include "ArrayList.cpp"//!!!!!!!!!!!注意加上这一句

using namespace std;

int main()
{
ArrayList<int> intArrayList(5);
system("PAUSE");
return 0;
}



/* 文件名: ArrayList.h
*
* 功能: 用数组描述的线性类声明
*
* 作者: zhoujun
* 时间: 2006-3-23
*
* 描述: Array_LinearList
*/
#ifndef ArrayList_H_
#define ArrayList_H_
#include <iostream>


template <class T>
class ArrayList
{
public:
ArrayList(int size = 10);
~ArrayList() { delete [] _List;}
bool IsEmpty();
int Length();
bool Find(int k, T& x) const;
int Search(const T& x) const;
ArrayList<T>& Insert(int k, const T& x);
ArrayList<T>& Delete(int k, T& x);
void OutPut(std::ostream& out) const;

private:
int _length;
T * _List;
int _size;
};

#endif

2006-03-25 12:57
快速回复:求助,数组实现的线性表编译错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018522 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved