error LNK2019: 无法解析的外部符号 "class std::basic_ostream
问题描述:用int类型取代template<class Type>一切正常,而用template<class Type>就出现代码中的问题,在VS2008和VS2010中测试,纠结了一天了,望高手指点,感激不尽
//CirQueue.h文件
#include <iostream>
using namespace std;
//循环队列类
template<class Type>
class CirQueue
{
public:
CirQueue(int size);
~CirQueue();
void Store(int n);//初始数据存入
friend ostream& operator<<(ostream& output,CirQueue<Type>& cq);
private:
int *data;
int maxSize;
int head,rear;
int length;
};
//构造函数
template<class Type>
CirQueue<Type>::CirQueue(int size)
{
if(size<1)
throw "空间大小有误!";
maxSize=size;
data=new int[maxSize];
head=0;
rear=0;
length=0;
}
//析构函数
template<class Type>
CirQueue<Type>::~CirQueue()
{
delete [] data;
maxSize=0;
head=rear=-1;
length=0;
cout<<"测试析构是否成功"<<endl;
}
//初始数据存入空队列
template<class Type>
void CirQueue<Type>::Store(int n)
{
if(n<1 || n>maxSize-1)
throw "输入的数据量大小小于1或超长!";
for(int i=0; i<n; i++)
{
cin>>data[i];
}
rear=n;
length=n;
}
//重载输出队列元素
template<class Type>
ostream& operator<<(ostream& output,CirQueue<Type>& cq)
{
output<<"测试一下"<<endl;
/*
int i=cq.head;
if(cq.length==0)
output<<"队列为空!"<<endl;
if(cq.length==1)
output<<"惟一元素:"<<cq.data[i]<<endl;
else
{
while(i!=cq.rear)
{
if(i==cq.head)
output<<"对头元素:"<<cq.data[i]<<endl;
else if(i==cq.rear-1)
output<<"对尾元素:"<<cq.data[i]<<endl;
else
output<<cq.data[i]<<endl;
i=(i+1)%cq.maxSize;//【妙】
}
}
*/
return output;
}
//CirQueue_main.cpp
#include <iostream>
using namespace std;
#include "CirQueue.h"
int main()
{
int size;
cout<<"请输入队列空间大小:";
cin>>size;
CirQueue<int> *cirQ;
try
{
cirQ=new CirQueue<int>(size);
}
catch(char *p)
{
cout<<p<<endl;
exit(1);
}
int n;
cout<<"初始数据存入"<<endl;
cout<<"请输入要存入的数据量大小:";
cin>>n;
try
{
cout<<"请输入这"<<n<<"个数:"<<endl;
cirQ->Store(n);
}
catch(char *p)
{
cout<<p<<endl;
exit(1);
}
int choice;
do
{
cout<<endl;
cout<<"1-进队"<<endl;
cout<<"2-出队"<<endl;
cout<<"3-返回对头元素"<<endl;
cout<<"4-返回队尾元素"<<endl;
cout<<"5-返回对头、队尾位置"<<endl;
cout<<"6-返回队列长度"<<endl;
cout<<"7-输出队列中的元素"<<endl;
cout<<"8-退出"<<endl;
cout<<endl;
cout<<"请输入选项:";
cin>>choice;
switch(choice)
{
case 7:
cout<<(*cirQ)<<endl;
break;
case 8:
break;
default:
cout<<"无此选项!"<<endl;
break;
}
}while(choice!=8);
delete cirQ;//①【重点】加上这个语句才执行析构函数
return 0;
}
/*
下面是连接错误(VS2008、VS2010)
1>CirQueue_main.obj : error LNK2019: 无法解析的外部符号 "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class CirQueue<int> &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@AAV?$CirQueue@H@@@Z),该符号在函数 __catch$_main$0 中被引用
1>F:\编程\CirQueue\Debug\CirQueue.exe : fatal error LNK1120: 1 个无法解析的外部命令
*/
...全文
相关推荐
vc++6.0初学者教程-16页
vc++6.0初学者教程__16页
MATLAB实现了PEM燃料电池中PFSA膜化学降解的23反应动力学模型。.zip
1.版本:matlab2014a/2019b/2024b 2.附赠案例数据可直接运行。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
产业园区运营负责人如何精准挖掘企业技术需求?.docx
产业园区运营负责人如何精准挖掘企业技术需求?
全球机场航空基础设施数据集86242处247国家或地区
地理空间与航空研究数据集:覆盖247个国家和地区的86242处已验证航空设施综合基准,从大型洲际枢纽机场到草地跑道、高山直升机停机坪与偏远极地冰跑道全面收录。每处设施包含跑道几何与标高数据、连接性指标、都会区临近度与地缘可及性等字段,弥补商业航空数据库仅覆盖约4000个IATA定期航班机场、通用航空与偏远救援机场分散于各国登记系统的碎片化问题。可用于GIS制图、航空经济研究、应急物流韧性分析与机器学习建模。CC0公共领域许可,适合地理信息研究者、航空分析师与GIS制图师使用。
VBScript002-ASCII
VBScript002-ASCII


