【发布时间】:2020-12-24 20:28:54
【问题描述】:
main Node<int> *head = takeInput() 内的行给出错误没有匹配函数调用“takeInput()”。你能帮我告诉我我在这里做的错误是什么,这样我以后就不会这样做了。谢谢!
#include<iostream>
using namespace std;
template<class T>
class Node{
public:
T data;
Node *next;
Node(T x){
data = x;
next = NULL;
}
};
template<typename T>
Node<T> * takeInput(){
T data;
cin>>data;
Node<T> *head = NULL;
Node<T> *tail = NULL;
while(data != -1){
Node<T> *newNode = new Node(data);
if(head == NULL){
head = newNode;
tail = newNode;
}else{
tail->next = newNode;
tail = tail->next;
}
cin>>data;
}
return head;
}
int main(){
Node<int> *head = takeInput();
cout<<head->data;
}
【问题讨论】:
标签: c++ function pointers linked-list main