簡體   English   中英

沒有參數列表的模板名稱“節點”的無效使用

[英]Invalid Use of template-name 'node' without an argument list

node.h

#ifndef node_h
#define node_h
using namespace std;
template<class Type> 
struct node { 
    node (Type v) : next(nullptr),data(v){}
    Type data; 
    node *next;

    }; 

#endif 

prioqueueS.cpp

#ifndef prioqueueS
#define prioqueueS 
#include "node.h"  
using namespace std;    
template <class type> 
class PrioQueueS { 
private: 
   node *head; 
   node *tail; 
};
#endif 

這當然不是我的全部課程,但這是我遇到的問題,我四處尋找她的明確答案,但沒有找到答案。 這是我的錯誤信息:

error: invalid use of template-name 'node' without an argument list
node *head;

如果有人能指出我正確的方向來解決這個問題,將不勝感激。

編輯:我意識到我忘記了

node<Type> head; 

所以我可能會刪除

node是模板類型。 要聲明node變量(甚至只是指向一個變量的指針),您需要為template參數指定一個值。 但是您沒有這樣做,所以編譯器抱怨的是:

#ifndef prioqueueS
#define prioqueueS 

#include "node.h"  
using namespace std;    

template <class type> 
class PrioQueueS { 
private: 
   node *head; // <-- here
   node *tail; // <-- here
};

#endif 

嘗試以下方法:

#ifndef prioqueueS
#define prioqueueS 

#include "node.h"  
using namespace std;    

template <class type> 
class PrioQueueS { 
private: 
   node<type> *head; // <-- here
   node<type> *tail; // <-- here
};

#endif

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM