| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 983 人关注过本帖, 1 人收藏
标题:编译时出现这个错误:函数 _main 中被引用
只看楼主 加入收藏
heyyroup
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2006-6-14
收藏(1)
 问题点数:0 回复次数:4 
编译时出现这个错误:函数 _main 中被引用
我在写线性表的程序的时候,单独编译的时候都没问题。但是在连接的时候出现很多错误。是在看不懂是什么意思,希望大家能帮帮忙。
我的源程序如下
//seqList.h
#ifndef SEQLIST_H_
#define SEQLIST_H_
const int DefaultSize=10;
template <class Type>
class SeqList
{
private:
int MaxSize;
int last;
Type *data;
public:
SeqList(int sz=DefaultSize);
~SeqList(){delete []data;}
int Length(){return last+1;} //返回线性表的实际长度
int Find(Type & x)const; //在线性表中查找元素X,查找成功返回其下标,否则返回-1
bool IsIn(Type & x)const; //判断x是否在线性表中
bool IsEmpty() const; //判断线性表是否为空
bool IsFull() const; //判断线性表是否已满
bool InsterElem(Type& x,int i); //在线性表中第i个元素插入x
bool DeleteElem(Type & x); //从线性表中删除元素x
int PriorElem(Type & x); //返回线性表中元素x的前驱元素
int NextElem(Type & x); //返回线性表中元素x的后继元素
Type Get(int i); //取得线性表中第i个元素的值
};
#endif
//seqList.cpp
#include "seqlist.h"
template <class Type>
SeqList<Type>::SeqList(int sz/* =DefaultSize */)
{
MaxSize=sz;
last=-1;
data=new Type[MaxSize];
}
template <class Type>
int SeqList<Type>::Find(Type & x)const
{
int i=0;
while(i<=last&&data[i]!=x)
i++;
if(i>last)
return -1;
else
return i;
}
template <class Type>
bool SeqList<Type>::IsIn(Type & x)const
{
int i=0;
int found=0;
while(i<=last&&!found)
if(data[i]!=x)
i++;
if(found)
return true;
else
return false;
}
template <class Type>
bool SeqList<Type>::IsEmpty()const
{
return last==0;
}
template <class Type>
bool SeqList<Type>::IsFull()const
{
return last==MaxSize-1;
}
template <class Type>
bool SeqList<Type>::InsterElem(Type & x,int i)
{
if(i<0||i>last||last==MaxSize-1)
return false;
else
{
last++;
for(int j=last;j>i;j--)
data[j]=data[j-1];
data[i]=x;
return true;
}
}
template <class Type>
bool SeqList<Type>::DeleteElem(Type & x)
{
int i=Find(x);
if(i>=0)
{
last--;
for(int j=i;j<=last;j++)
data[j]=data[j+1];
return true;
}
return false;
}
template <class Type>
int SeqList<Type>::PriorElem(Type & x)
{
int i=Find(x);
if(i>0 && i<=last)
return i-1;
else return -1;
}
template <class Type>
int SeqList<Type>::NextElem(Type & x)
{
int i=Find(x);
if(i>=0 && i<last)
return i+1;
else
return -1;
}
template <class Type>
Type SeqList<Type>::Get(int i)
{
if(i<0||i>last)
return NULL;
else
return data[i];
}
//Test.cpp
#include <iostream>
#include "seqlist.h"
using std::endl;
using std::cout;
int main()
{
SeqList<int> mylist;
if (mylist.IsEmpty())
{
cout<<"表为空,表长为:"<<mylist.Length()<<endl;
}
cout<<"为表赋值"<<endl;
int a[10]={2,3,4,5,6,7,8,9,10,11};
for(int i=0;i<10;i++)
mylist.InsterElem(a[i],i+1);
cout<<"表长为:"<<mylist.Length()<<endl;
cout<<"表中元素为:"<<endl;
for (int i=0;i<mylist.Length();i++)
{
cout<<i+1<<": "<<mylist.Get(i)<<endl;
}
if (mylist.IsFull())
{
cout<<"表已满"<<endl;
}
int x=8;
if (mylist.IsIn(x))
{
cout<<x<<"为表中第"<<mylist.Find(x)<<"号元素"<<endl;
}
cout<<"从表中删除元素"<<endl;
if(mylist.DeleteElem(x))
{
cout<<"删除成功"<<endl;
cout<<"目前表中元素为"<<endl;
for (int i=0;i<mylist.Length();i++)
{
cout<<i+1<<":"<<mylist.Get(i)<<endl;
}
}
cout<<"向表中插入元素"<<endl;
x=12;
if (mylist.InsterElem(x,2))
{
cout<<"插入成功"<<endl;
cout<<"表长为"<<mylist.Length()<<endl;
cout<<"表中元素为"<<endl;
for(int i=0;i<mylist.Length();i++)
cout<<i+1<<":"<<mylist.Get(i)<<endl;
}
x=9;
int j=mylist.PriorElem(x);
if(j!=-1)
cout<<"元素x的前驱元素为"<<mylist.Get(j)<<endl;
j=mylist.NextElem(x);
if (j!=-1)
cout<<"元素X的后继元素为"<<mylist.Get(j)<<endl;
return 0;
}
在生成执行文件的时候出现如下错误;
已启动生成: 项目: 顺序表, 配置: Debug Win32 ------
正在链接...
TestList.obj : error LNK2019: 无法解析的外部符号 "public: int __thiscall SeqList<int>::NextElem(int &)" (?NextElem@?$SeqList@H@@QAEHAAH@Z),该符号在函数 _main 中被引用
TestList.obj : error LNK2019: 无法解析的外部符号 "public: int __thiscall SeqList<int>::PriorElem(int &)" (?PriorElem@?$SeqList@H@@QAEHAAH@Z),该符号在函数 _main 中被引用
TestList.obj : error LNK2019: 无法解析的外部符号 "public: bool __thiscall SeqList<int>::DeleteElem(int &)" (?DeleteElem@?$SeqList@H@@QAE_NAAH@Z),该符号在函数 _main 中被引用
TestList.obj : error LNK2019: 无法解析的外部符号 "public: int __thiscall SeqList<int>::Find(int &)const " (?Find@?$SeqList@H@@QBEHAAH@Z),该符号在函数 _main 中被引用
TestList.obj : error LNK2019: 无法解析的外部符号 "public: bool __thiscall SeqList<int>::IsIn(int &)const " (?IsIn@?$SeqList@H@@QBE_NAAH@Z),该符号在函数 _main 中被引用
TestList.obj : error LNK2019: 无法解析的外部符号 "public: bool __thiscall SeqList<int>::IsFull(void)const " (?IsFull@?$SeqList@H@@QBE_NXZ),该符号在函数 _main 中被引用
TestList.obj : error LNK2019: 无法解析的外部符号 "public: int __thiscall SeqList<int>::Get(int)" (?Get@?$SeqList@H@@QAEHH@Z),该符号在函数 _main 中被引用
TestList.obj : error LNK2019: 无法解析的外部符号 "public: bool __thiscall SeqList<int>::InsterElem(int &,int)" (?InsterElem@?$SeqList@H@@QAE_NAAHH@Z),该符号在函数 _main 中被引用
TestList.obj : error LNK2019: 无法解析的外部符号 "public: bool __thiscall SeqList<int>::IsEmpty(void)const " (?IsEmpty@?$SeqList@H@@QBE_NXZ),该符号在函数 _main 中被引用
TestList.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall SeqList<int>::SeqList<int>(int)" (??0?$SeqList@H@@QAE@H@Z),该符号在函数 _main 中被引用
E:\C++程序\数据结构练习\顺序表\Debug\顺序表.exe : fatal error LNK1120: 10 个无法解析的外部命令

我是在vs2005中编译的
搜索更多相关主题的帖子: main 函数 编译 
2007-10-08 19:23
succubus
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:635
专家分:1080
注 册:2007-10-7
收藏
得分:0 
模板在没有实例化之前是无法编译的,因为没有使用类型实例化的模板是不能生成代码的。

[url=http:///view/aDU1]/image/aDU1.gif" border="0" />[/url]
2007-10-08 20:01
heyyroup
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2006-6-14
收藏
得分:0 
不是很明白。能说的具体点吗?
2007-10-08 20:24
heyyroup
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2006-6-14
收藏
得分:0 
翻书找到问题的解决方法了,谢谢

2007-10-08 20:42
succubus
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:635
专家分:1080
注 册:2007-10-7
收藏
得分:0 
刚吃饭去了
问题解决了就好

[url=http:///view/aDU1]/image/aDU1.gif" border="0" />[/url]
2007-10-08 21:12
快速回复:编译时出现这个错误:函数 _main 中被引用
数据加载中...
 
   



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

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