模板中的编译器错误 [英] Compiler error in template

查看:97
本文介绍了模板中的编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个头文件和一个cpp文件.

I have a header file and a cpp file.

//////Node.h
	namespace Collections
	{
		/* Node */
		template<typename T>
		class Node
		{
		public:
			T element;
			Node *next;
			
			Node();
			Node(T element);
		};
	} // end namespace Collections





///// Node.cpp
#include "LinkedList.h"

	namespace Collections
	{
		template<typename T>
		Node<t>::Node()
		{
			next = NULL;
		}

		template<typename T>
		Node<t>::Node(T element)
		{
			this->element = element;
			next = NULL;
		}
	} // end namespace Collections


// app.cpp
// omit some "include"......
#include "collections/linkedlist.h"

using namespace std;
using namespace Collections;

int main()
{
	Node<string> *head;
	
	head = new Node<string>();
	head->element = "Nicky";
	head->next = NULL;
	tail = head;
	
	do
	{
		cout << tail->element << endl;
	}
	while(tail = tail->next);

	return 0;
}
</t></t>


则由于错误我无法编译项目:
错误LNK2019:无法解决外部符号" public:__thiscall Collections :: Node< class> ;, class std :: allocator< char> > > :: Node< class> ;、类std :: allocator< char> > >(无效)(?? 0?$ Node @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@@ Collections @@ QAE @ XZ) "

谁能帮我?这让我很困惑.

而且,如果我将代码从CPP文件复制到头文件中,我也可以进行编译....


then I CANNOT compile the project because of the error:
error LNK2019: cannot solve the external symbol ""public: __thiscall Collections::Node<class>,class std::allocator<char> > >::Node<class>,class std::allocator<char> > >(void)" (??0?$Node@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Collections@@QAE@XZ)"

Can anyone help me? It makes me confusing a lot..

And I CAN compile if I copy the code from CPP file to header file....

推荐答案

Node @ V?


basic_string @ DU?
basic_string@DU?


char_traits @ D @ std @@ V?
char_traits@D@std@@V?


这篇关于模板中的编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆