나는 C++에서 연결된 목록을 구현하도록 요청받는 작업을하고 있습니다. 지금까지는 새로운 목록을 만들 때를 제외하고 모든 것이 훌륭하게 작동합니다. 내 방법은 create_list()
입니다. 내용과 ID 번호를 Field
에 할당하고 GetNext()
으로 전화를 걸면 오류 메시지가 나타납니다. Request for member 'GetNext()' in 'Node' which is a non-class type '*Field'.
저는 C++ 구문 및 객체 지향 프로그래밍에 아직 익숙하지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까? 내 변수 Node
이 클래스 유형 Field
...이라는 라인 Field *Node = new Field(SIZE, EMPTY);
을 사용하여 생각 했습니까?C++ 연결된 목록 구현
#include <iostream>
#include <ctype.h>
using namespace std;
typedef enum { EMPTY, OCCUPIED } FIELDTYPE;
// Gameboard Size
int SIZE;
class Field {
private:
int _SquareNum;
FIELDTYPE _Content;
Field* _Next;
public:
// Constructor
Field() { }
// Overload Constructor
Field(int SquareNum, FIELDTYPE Entry) { _SquareNum = SquareNum; _Content = Entry; }
// Get the next node in the linked list
Field* GetNext() { return _Next; }
// Set the next node in the linked list
void SetNext(Field *Next) { _Next = Next; }
// Get the content within the linked list
FIELDTYPE GetContent() { return _Content; }
// Set the content in the linked list
void SetContent(FIELDTYPE Content) { _Content = Content; }
// Get square/location
int GetLocation() { return _SquareNum; }
// Print the content
void Print() {
switch (_Content) {
case OCCUPIED:
cout << "Field " << _SquareNum << ":\tOccupied\n";
break;
default:
cout << "Field " << _SquareNum << ":\tEmpty\n";
break;
}
}
}*Gameboard;
여기 내 create_list() 방법 : 당신은 Node.GetNext()
를 호출하고
void create_list()
{
int Element;
cout << "Enter the size of the board: ";
cin >> SIZE;
for(Element = SIZE; Element > 0; Element--){
Field *Node = new Field(SIZE, EMPTY);
Node.GetNext() = Gameboard; // line where the error is
Gameboard = Node;
}
}
끝내 주셔서 감사합니다 .... 실제로 생각해 보면 실제로 더 의미가 있습니다 .... – accraze