泛型模版类出现了LNK2019: 无法解析的外部符号错误
来源:互联网 发布:职业规划测评软件 编辑:程序博客网 时间:2024/04/28 03:02
我们在写程序的大部分时间都不会去考虑在已有的知识上出现的匮乏,前两天用C++写了一个顺序表,结果却不尽人意,这个或许是因为人生就是这样,在你已知的知识当中出现的知识漏洞你会很难发现,这里还是感谢一下syc大哥,每次在VC驿站上发帖子,他都给我回复了,也就是syc让我更加的喜欢VC驿站。
行了,谈谈出现的错误
这里是我之前出错的代码
http://www.cctry.com/thread-256893-1-1.html
这里我放上了我成功后的代码
SeqList.h
#include<iostream>#include<stdio.h>//默认的顺序表大小const int defaultsize= 10;//类template<typename DateType>class SeqList{public:SeqList(int size = defaultsize){//判断对应的顺序表长度if (size > 0){maxSize = size;//数据数组eml = new DateType[size];}}//析构函数~SeqList(){//申请的数组不为空时进行释放if (eml != NULL){delete []eml;eml = NULL;}}int getLength(){return curLength;}//插入bool insertElem(DateType e);//删除bool delElem(int index);//查找DateType findElem(int index);//更改bool changeElem(int index, DateType e);private:DateType *eml;int maxSize;int curLength;};//插入template<class DateType>bool SeqList<DateType>::insertElem(DateType e){if (curLength < maxSize){eml[curLength] = e;curLength++;return true;}std::cout << "insertElem function the Array is full" << std::endl;return false;}//删除template<class DateType>bool SeqList<DateType>::delElem(int index){if (curLength > index && index >= 0){for (int i = index; i < curLength; i++){eml[i] = eml[i + 1];}curLength--;return true;}std::cout << "delElem function wrong index" << std::endl;return false;}//查找template<class DateType>DateType SeqList<DateType>::findElem(int index){if (index < 0 && index >= curLength){std::cout << "findElem function wrong index" << std::endl;return NULL;}return eml[index];}//更改template<class DateType>bool SeqList<DateType>::changeElem(int index, DateType e){if (index >= 0 && index < curLength){eml[index] = e;return true;}std::cout << "changElem function wrong index" << std::endl;return false;}
测试体
#include "SeqList.h"#include <iostream>//success in day 09-01//模版类的声明和实现必须写在同一个头文件中,否则就无法找到类中对应的函数int main(){//使用泛型类,并调用构造函数SeqList<int> list(10);//插入值for (int i = 0; i < 10; i++){list.insertElem(i);}//显示值for (int i = 0; i < list.getLength(); i++){std::cout << list.findElem(i) << std::endl;}//更改值list.changeElem(3, 5);list.delElem(4);//显示值for (int i = 0; i < list.getLength(); i++){std::cout << list.findElem(i) << std::endl;}char a[10];std::cin >> a;}
这里也就是说出现了一个小小的问题,就是模版类的定义和实现体一般要卸载同一个头文件中。
下面来源于网上:
在C++标准中没有明确规定,模版类的定义和实现体必须放置到同一个文件中,因为模版类是在预编译期间进行,如果写在两个文件中,增加了编译器的实现难度,所以大多数编译器一般都将模版类的定义和实现放置在同一个文件中。VS2005支持了模版类的分离编写,但是他又检测不出来很多其他的错误,这不得不说还是需要一个天才的大脑来解决这个问题
0 0
- 泛型模版类出现了LNK2019: 无法解析的外部符号错误
- error LNK2019: 无法解析的外部符号 错误解析
- 编译出现的错误- error LNK2019: 无法解析的外部符号 _GetProcessMemoryInfo@12
- 出现error LNK2019: 无法解析的外部符号错误的诊断
- 项目添加UNICODE支持时,出现链接错误error LNK2019: 无法解析的外部符号 _WinMain
- Qt 出现了 Qt error LNK2019: 无法解析的外部符号 "public: __thiscall 怎么解决
- "error LNK2019: 无法解析的外部符号"错误的解决办法
- 【错误笔记】error LNK2019: 无法解析的外部符号 _cvHaarDetectObjects
- C++ 错误error LNK2019: 无法解析的外部符号
- vs2005 调试错误error LNK2019: 无法解析的外部符号
- Qt中错误:LNK2019: 无法解析的外部符号
- C++ error LNK2019: 无法解析的外部符号 错误解决方案
- 错误error LNK2019: 无法解析的外部符号 _auxDIBImageLoadW@4
- 出现错误:无法解析的外部符号
- C++中使用类模板时出现:“error LNK2019: 无法解析的外部符号”的解决办法
- 配置openmesh总是出现error LNK2019: 无法解析的外部符号此类问题的解决办法
- Qt引用新类,出现LNK2019: 无法解析的外部符号
- error LNK2019: 无法解析的外部符号
- 【翻译自mos文章】访问Oracle Database的知名的Data Providers for .NET
- 主流蓝牙BLE控制芯片详解(2):CSR BC6130
- 平庸是一种罪恶、无知是一种恶意
- 5 Principles in Human Computer Interaction
- CS0234: 命名空间“System.Web.Mvc”中不存在类型或命名空间名称“Ajax”(是否缺少程序集引用?) 解决办法
- 泛型模版类出现了LNK2019: 无法解析的外部符号错误
- I/O复用 select poll epoll
- Mac OS X升级新版本svn(命令行svn)
- 简化SQL式计算之行间计算
- Android万能适配器(二)封装Adapter
- 浅谈JAVA应用技能
- 编译原理:第一节
- 新起点
- unix网络编程前奏