2012-09-24 3 views
1

그래서 노드를 가지고 놀았으며 테스트하려고 할 때이 오류가 계속 발생했습니다. 괄호를 사용하면 list.에서이 오류가 발생합니다. - "표현식에 클래스 유형이 있어야합니다!"표현식에 클래스 유형이 있어야합니까?

괄호를 사용하지 않으면이 오류가 list, insertdisplay-이 "액세스 할 수 없습니다."에 표시됩니다.

Main()에서 LList를 선언 할 때 발생합니다. 무슨 일이 일어나고 있고 왜 이래?

내 드라이버

#include "LList.h" 
#include <iostream> 
using namespace std; 

int main() 
{ 
    LList<int> list; 
    bool test = list.insert(5); 
    list.display(); 

    return 0; 
} 

클래스 LList

#include "Nodes.h" 
#ifndef LLIST_H 
#define LLIST_H 

template<typename TYPE> 
class LList 
{ 
    Node<TYPE>* front; 
    LList(); 
    ~LList(); 
    bool insert(const TYPE& dataIn); 
    void display() const; 
}; 

template<typename TYPE> 
LList<TYPE>::LList() 
{ 
    front = null; 
}; 

template<typename TYPE> 
LList<TYPE>::~LList() 
{ 
    Node<TYPE>* temp; 
    while(front) 
    { 
     temp = front; 
     front = fornt -> next; 
     delete temp; 
    } 
}; 

template<typename TYPE> 
bool LList<TYPE>::insert(const TYPE& dataIn) 
{ 
    bool success = false; 
    Node<TYPE> pBefore = null; 
    Node<TYPE> pAfter = front; 

    while(pAfter && PAfter->data < dataIn) 
    { 
     pBefore = pAfter; 
     pAfter = pAfter->next; 
    } 

    if(Node<TYPE>* store = new Node<TYPE>) 
     store->data = dataIn 

    return success; 
}; 

template<typename TYPE> 
void LList<TYPE>::display() const 
{ 
    TYPE* temp = front; 
    while(front && temp->next != null) 
    { 
     cout << temp->data << endl; 
    } 
}; 

#endif 

클래스 노드

#ifndef NODES_H 
#define NODES_H 

template<typename TYPE> 
struct Node 
{ 
    Node<TYPE>* next; 
    TYPE data; 
    Node(); 
    Node(TYPE d, Node<TYPE> n); 
}; 
template<typename TYPE> 
Node<TYPE>::Node() 
{ 
    data = 0; 
    next = null; 
}; 
template<typename TYPE> 
Node<TYPE>::Node(TYPE d, Node<TYPE> n) 
{ 
    data = d; 
    next = n; 
}; 

#endif 
+0

"괄호를 사용하면 ..."어디에서? –

+0

'LList list;와'LList list();'에 오류가 있습니다. –

답변

1

귀하의 오류가됩니다 클래스 선언의 결과 :

template<typename TYPE> 
class LList 
{ 
    Node<TYPE>* front; 
    LList(); 
    ~LList(); 
    bool insert(const TYPE& dataIn); 
    void display() const; 
}; 

실마리가 "This is incescesible"오류가 있습니다. 액세스 수정자를 제공하지 않았기 때문에이 클래스의 모든 구성원은 기본적으로 private이됩니다. 이 문제를 해결하려면, 당신은 단지 클래스의 공공 및 민간 부분에 라벨을해야이 변경으로

template<typename TYPE> 
class LList 
{ 
    public: 
     LList(); 
     ~LList(); 
     bool insert(const TYPE& dataIn); 
     void display() const; 

    private: 
     Node<TYPE>* front; 
}; 

, 당신의 코드 또는 list에 대한 변수 선언의 끝에 괄호없이 작동합니다.

관련 문제