어떻게 링크 된 목록에 클래스의 구조를 추가합니까? 클래스는 DVD 제목과 길이를 갖는 구조를 사용합니다. 각 DVD는이 구조체의 인스턴스가되며 링크 된 목록에 저장됩니다. 또한, 연결리스트 내가 class DVD
에서 구조체를 제거하고 바로 넣으면 링크 된 목록에 구조 추가
template <class T>
class LinkedList1
{
private:
// Declare a structure
struct discList
{
T value;
struct discList *next; // To point to the next node
};
discList *head; // List head pointer
public:
// Default Constructor
LinkedList1()
{ head = NULL; }
// Destructor
~LinkedList1();
// Linked list operations
void appendNode(T);
void insertNode(T);
void deleteNode(T);
void displayList() const;
};
그것이
// Declare a DVD object
DVD dvd(105, "Spider Man"); // length and title
// Declare a linked list object with the data type of the struct disc.
LinkedList1<DVD> movie;
// or
LinkList1<DVD::my_disc> movie;
// and then append it
movie.appendNode(dvd)
수 있을까요 구조
class DVD
{
private:
struct disc
{
int length;
string title;
}my_disc;
public:
// Constructor
DVD(int, string);
};
링크 된 목록의 데이터 유형을 가져야한다 데이터 멤버 length
및 title
을 전용 멤버로 사용하면 LinkedList1<DVD> movie;
은 t를 추가 할 수 있음을 알고 있습니다. 그 노드. 구조체가 날 버리고 있어요. "링크 된 목록의 데이터 형식은 구조체"이어야합니다. 내게는 LinkedList1<disc>movie;
처럼 보입니다. disc
은 구조체의 이름입니다. 이견있는 사람?
내 강사의 지시 사항 이었지만 알아 냈습니다. – Lilspree
"연결된 목록의 데이터 형식은 구조체 매개 변수가"DVD 형식 "으로 특수화 될 구조로 변환되어야합니다. 여기서"데이터 형식 "은"목록 노드의 콘텐츠 형식 "에 대한 동의어로 사용되며 "구조체"는 할당 텍스트에 정의 된 특정 구조체'DVD '의 동의어로 사용되었습니다. 초보자를 가르 칠 때 정확한 표현이 필수적이라는 것을 상기시켜줍니다. – starturtle