【发布时间】:2020-10-02 00:54:15
【问题描述】:
我有以下代码在“Node.cpp”文件中显示错误
#include "stdafx.h"
#include<iostream>
using namespace std;
template<typename X>//think error is here
class Node
{
private:
X data;
Node *prev,*next;
public:
Node(X data)
{
this->data=data;
prev=next=NULL;
}
~Node(){}
X getData()
{
return data;
}
};
这里是 DoubleList 文件
#include "stdafx.h"
#include <iostream>
#include "conio.h"
#include "Node.cpp"
template<typename T>
class DoubleList
{
private:
public:
Node *first, *last;
DoubleList()
{
first=last=NULL;
}
~DoubleList()
{}
void insertLast(T data)
{
Node *t=new Node(data)
if(first==last)
{
first=t;
}
last->next=t;
t->prev=last;
last=t;
cout<<"\nNode having data ["<<data<<"] is inserted successfully";
}
void insertFirst(T data)
{
Node *t=new Node(data)
if(first==last)
{
first=t;
}
first->prev=t;
t->next=first;
first=t;
cout<<"\nNode having data ["<<data<<"] is inserted successfully";
}
void display()
{
Node *t=first;
cout<<"\nPrevious Data Next"
while(t->next!=NULL)
{
cout<<t->prev<<" "<<t->data<<" "<<t->next<<endl;
t=t->next;
}
}
};
我不知道为什么会收到此错误。我也检查了类似的问题,但他们没有解决我的问题。我试图避免头文件的混乱,我只创建了 cpp 文件。我试图使它们成为通用类型,但这个错误在我之上。我不知道该怎么办。
【问题讨论】:
标签: c++ visual-c++ template-classes