我创建一个链表类时遇到了一个奇怪的问题。 [英] I met a strange problem when I create a linked list class .
问题描述
--------------------------------------这是我的代码----- -----------------------------------
#ifndef _LIST_H_
#define _LIST_H_
模板< typename t = >
struct Num {
T num;
Num * next;
};
template < typename t = 跨度>>
class 列表{
私人:
Num< t> * PHEAD;
public :
List();
int count();
void create(T * a, int n);
void list_();
void add(T key, int n);
void Swapat( int a, int b);
void Swapnum(T num1,T num2);
int& at( int n);
void Sort();
void del( int n);
void delTheSame();
};
#endif
------- ------------并且,一些成员函数如下:-----------------------
模板< typename t = 跨度>>
List< t> :: List(){
pHead = NULL;
}
模板< typename t = 跨度>>
void 列表< t> :: create(T * a, int n){
Num< t> * pTail = NULL;
for ( int i = 0 ; i< n; ++ i){
Num< t> * t = new Num< t> ;;
t-> num = a [i];
t-> next = NULL;
if (pHead == NULL){
pHead = t;
pTail = pHead;
}
其他 {
pTail-> next = t;
pTail = t;
}
}
}
模板< typename t = >
void 列表< t> :: list_(){
Num< t> * t = pHead;
while (t!= NULL){
cout<< t-> num<< ;
t = t-> next;
}
cout<< ENDL;
}
------------------------------ ----但是,问题来了------------------------------------------ -
严重级代码描述项目文件行
错误LNK1120 3未解析的外部测试C:\Users\Sar.Kerson \Desktop\Test1 \\ \\Test \Debug \ Test.exe 1
严重级代码说明项目文件行
错误LNK2019未解析的外部符号public:__thiscall List :: List(void)(?? 0?$ List @功能主要测试C中引用了H @@ QAE @ XZ:\ Users \Sar.Kerson \Desktop\Test1\Test \Test \ main.obj 1
严重性代码描述项目文件行
错误LNK2019未解析的外部符号public:void __thiscall List :: create(int *,int)(?create @?$ List @ H @@ QAEXPAHH @ Z)在函数_main中引用测试C:\ Users \Sar.Kerson \Desktop\Test1\Test \Test \ main.obj 1
严重性代码说明项目文件行
错误LNK2019未解析的外部sym bolpublic:void __thiscall List :: list(void)(?list _ @?$ List @ H @@ QAEXXZ)在函数_main测试C中引用:\ Users \Sar.Kerson \Desktop\Test1 \ Test\Test\main.obj 1
------------------------- - - - - - - 请帮忙 - - - - - - - - - - - - - - - - - - -----------
我尝试了什么:
如果我不使用模板,我可以运行。
我不知道如何解决问题。
你能告诉我吗?怎么做。
List @ H @@ QAE @ XZ)在函数main test C中引用:\ Users \Sar.Kerson \Desktop \\ \\ Test1\Test \Test \ main.obj 1
严重性代码说明项目文件行
错误LNK2019未解析的外部符号public:void __thiscall List :: create(int *,int)( ?create @?
List @ H @@ QAEXPAHH @ Z)在函数_main测试C中引用:\ Users \Sar.Kerson \Desktop \ Test1 \Test \Test \ main.obj 1
严重性代码说明项目文件行
错误LNK2019未解析的外部符号public:void __thiscall List :: list(void)(?list_函数_main中引用的@?
List @ H @@ QAEXXZ测试C:\ Users \Sar.Kerson \Desktop\Test1 \Test \Test \ main .obj 1
-------------------------------- - - -请帮忙 - - - - - - - - - - - - - - - - - - - - - - ----
我尝试了什么:
如果我不要使用模板,我可以运行。
我不知道如何解决问题。
你能告诉我怎么做。
--------------------------------------Here are my codes----------------------------------------
#ifndef _LIST_H_
#define _LIST_H_
template <typename t="">
struct Num {
T num;
Num *next;
};
template <typename t="">
class List {
private:
Num<t>* pHead;
public:
List();
int count();
void create(T *a, int n);
void list_();
void add(T key, int n);
void Swapat(int a, int b);
void Swapnum(T num1, T num2);
int& at(int n);
void Sort();
void del(int n);
void delTheSame();
};
#endif
-------------------And, some of the member functions are as following:-----------------------
template <typename t="">
List<t>::List() {
pHead = NULL;
}
template <typename t="">
void List<t>::create(T *a, int n) {
Num<t> *pTail = NULL;
for (int i = 0; i < n; ++i) {
Num<t> *t = new Num<t>;
t->num = a[i];
t->next = NULL;
if (pHead == NULL) {
pHead = t;
pTail = pHead;
}
else {
pTail->next = t;
pTail = t;
}
}
}
template <typename t="">
void List<t>::list_() {
Num<t> *t = pHead;
while (t != NULL) {
cout << t->num << " ";
t = t->next;
}
cout << endl;
}
----------------------------------But, problems came-------------------------------------------
Severity Code Description Project File Line
Error LNK1120 3 unresolved externals Test C:\Users\Sar.Kerson\Desktop\Test1\Test\Debug\Test.exe 1
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "public: __thiscall List::List(void)" (??0?$List@H@@QAE@XZ) referenced in function main Test C:\Users\Sar.Kerson\Desktop\Test1\Test\Test\main.obj 1
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "public: void __thiscall List::create(int *,int)" (?create@?$List@H@@QAEXPAHH@Z) referenced in function _main Test C:\Users\Sar.Kerson\Desktop\Test1\Test\Test\main.obj 1
Severity Code Description Project File Line
Error LNK2019 unresolved external symbol "public: void __thiscall List::list(void)" (?list_@?$List@H@@QAEXXZ) referenced in function _main Test C:\Users\Sar.Kerson\Desktop\Test1\Test\Test\main.obj 1
-------------------------------------Please help-----------------------------------------------
What I have tried:
if I don't use the template, I can run.
I don't know how to solve the problem.
Could you please tell me how to do this.
List@H@@QAE@XZ) referenced in function main Test C:\Users\Sar.Kerson\Desktop\Test1\Test\Test\main.obj 1 Severity Code Description Project File Line Error LNK2019 unresolved external symbol "public: void __thiscall List::create(int *,int)" (?create@?
List@H@@QAEXPAHH@Z) referenced in function _main Test C:\Users\Sar.Kerson\Desktop\Test1\Test\Test\main.obj 1 Severity Code Description Project File Line Error LNK2019 unresolved external symbol "public: void __thiscall List::list(void)" (?list_@?
List@H@@QAEXXZ) referenced in function _main Test C:\Users\Sar.Kerson\Desktop\Test1\Test\Test\main.obj 1
-------------------------------------Please help-----------------------------------------------
What I have tried:
if I don't use the template, I can run.
I don't know how to solve the problem.
Could you please tell me how to do this.
这篇关于我创建一个链表类时遇到了一个奇怪的问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!