1
저는 C++ 프로그래밍을 처음 사용합니다.C++ 오류 : 필드에 불완전한 형식이 있습니다 - 자체 클래스 개체를 선언합니다
#ifndef NODE_H
#define NODE_H
class Node
{
public:
Node();
Node(int);
virtual ~Node();
Node(const Node& other);
int getValue() { return value; }
void setValue(int val) { value = val; }
Node getPrev() { return prev; }
void setPrev(Node val) { prev = val; }
Node getNext() { return next; }
void setNext(Node val) { next = val; }
private:
int value; //!< Member variable "value"
Node prev; //!< Member variable "prev"
Node next; //!< Member variable "next"
};
#endif // NODE_H
그것은 말한다 :
error field 'prev' has incomplete type
error field 'next' has incomplete type
내가 포인터/참조를 사용하는 경우, 프로그램이 잘 작동 여기 내 코드입니다. 왜이 메커니즘이 존재합니까? 어떻게 포인터/참조하지 않고 그것을 할 수 있습니까? 답변 해 주셔서 감사합니다.
모든 '노드'에 'int'와 두 개의 '노드'가 포함되어 있으면 그 크기는 무한대가됩니다. 아마 당신이 원하는 것이 아닙니다. – Quentin
* "포인터/참조없이 어떻게 할 것인가?"* 긴 이야기 : 당신은 할 수 없습니다. –
다른 방법 : https://stackoverflow.com/questions/6349822/incomplete-type-in-class-which-has-a-member-of-the-same-type-of-the-class-itse –