2013-09-27 79 views
1

難以獲取編譯的主要方法。 該錯誤是在第10行:'*'令牌之前缺少模板參數

missing template argument before * token. 
myChain was not declared in this scoop 
expected type-specifier before 'chain' 
expected ';' before 'chain' 

下面是其中發生錯誤的代碼。

#include <iostream> 
#include "chain.h" 
#include "IOcode.h" 
#include "chainNode.h" 

using namespace std; 

int main(){ 

    chain *myChain=new chain(10); 
    userInputOutput(myChain, "chain"); 
} 

chainNode.h依賴性

#ifndef chainNode_ 
#define chainNode_ 

template <class T> 
struct chainNode 
{ 
    // data members 
    T element; 
    chainNode<T> *next; 

    // methods 
    chainNode() {} 
    chainNode(const T& element) 
     {this->element = element;} 
    chainNode(const T& element, chainNode<T>* next) 
     {this->element = element; 
     this->next = next;} 
}; 

#endif 

chain.h依賴性 類定義爲鏈。

#ifndef chain_ 
#define chain_ 

#include<iostream> 
#include<sstream> 
#include<string> 
#include "linearList.h" 
#include "chainNode.h" 
#include "myExceptions.h" 

class linkedDigraph; 
template <class T> class linkedWDigraph; 

template<class T> 
class chain: public linearList 
{ 
    friend class linkedDigraph; 
    friend class linkedWDigraph<int>; 
    friend class linkedWDigraph<float>; 
    friend class linkedWDigraph<double>; 
    public: 
     // constructor, copy constructor and destructor 
     chain(int initialCapacity = 10); 
     chain(const chain<T>&); 
     ~chain(); 

     // ADT methods 
     bool empty() const {return listSize == 0;} 
     int size() const {return listSize;} 
     T& get(int theIndex) const; 
     int indexOf(const T& theElement) const; 
     void erase(int theIndex); 
     void insert(int theIndex, const T& theElement); 
     void output(ostream& out) const; 

    protected: 
     void checkIndex(int theIndex) const; 
      // throw illegalIndex if theIndex invalid 
     chainNode<T>* firstNode; // pointer to first node in chain 
     int listSize;    // number of elements in list 
}; 

IOcode.h依賴

#include <iostream> 
#include "linearList.h" 

using namespace std; 

void userInputOutput (linearList* l, string dataStructure); 

回答

7

這個類是模板化的,這意味着你必須指定一個類型填寫爲模板,所以你會說

chain<string> *myChain=new chain<string>(10); 

代替

chain *myChain=new chain(10); 

,例如,如果你想使用這個鏈的字符串。