안녕하세요. 저는이 문제에 대한 해결책을 찾기 위해 여러 곳에서 조사를 해왔으며 ListNode를 정의하는 여러 가지 방법을 시도했습니다. cpp 파일. 어떤 이유로 struct는 .cpp 파일과 공유 할 수 없습니다. 어떤 도움이라도 대단히 감사하겠습니다. 감사헤더 파일의 개인 회원이 cpp 파일에서 작동하지 않는 이유를 알아낼 수 없습니다.
.H 파일 :
#ifndef SORTEDLIST_H
#define SORTEDLIST_H
#include "Student.h"
/*
* SortedList class
*
* A SortedList is an ordered collection of Students. The Students are ordered
* from lowest numbered student ID to highest numbered student ID.
*/
class SortedList {
public:
SortedList();
// Constructs an empty list.
bool insert(Student *s);
// If a student with the same ID is not already in the list, inserts
// the given student into the list in the appropriate place and returns
// true. If there is already a student in the list with the same ID
// then the list is not changed and false is returned.
Student *find(int studentID);
// Searches the list for a student with the given student ID. If the
// student is found, it is returned; if it is not found, NULL is returned.
Student *remove(int studentID);
// Searches the list for a student with the given student ID. If the
// student is found, the student is removed from the list and returned;
// if no student is found with the given ID, NULL is returned.
// Note that the Student is NOT deleted - it is returned - however,
// the removed list node should be deleted.
void print() const;
// Prints out the list of students to standard output. The students are
// printed in order of student ID (from smallest to largest), one per line
private:
// Since ListNodes will only be used within the SortedList class,
// we make it private.
struct ListNode {
Student *student;
ListNode *next;
};
ListNode *head; // pointer to first node in the list
};
#endif
.cpp 파일 :
#include <iostream>
#include "SortedList.h"
using namespace std;
SortedList::SortedList() : head(NULL){}
Student SortedList::*find(int studentID){
ListNode *current;
current = head;
if(current != NULL){
while(current != NULL){
if(current.student.getID() == studentID){
return current.student;
}
current = current.next;
}
}
return NULL;
}
되는 관련 오류 : C : 기능 Student SortedList::* find(int)': 12 C:\Users\Charles\Desktop\SortedList.cpp
ListNode '선언되지 않은에서 \ 사용자 \ 찰스 \ 바탕 화면 \ SortedList.cpp (이 기능을 처음 사용)
인가 그 코드에서 실제로 발생한 * 첫 번째 오류입니까? 항상 순서대로 오류를 해결하십시오. 컴파일러에서 오류가 발생하면 컴파일을 계속 시도하고 더 많은 오류 메시지를 표시 할 수 있도록 의미가 무엇인지 가정합니다.하지만 나중에 오류는 컴파일러의 잘못된 가정의 부작용입니다. 목록의 중간에있는 오류에 대한 작업을 시작하면 실제로 오류가 아닌 것을 수정하려고 시간을 낭비하게됩니다. 항상 맨 위에서 시작하십시오. –
위의 내용은 좋은 충고입니다. 그러나 필자는이 스텁 (stub) 정의를 사용하여 직접 테스트 컴파일 한 결과 첫 번째 오류가 발생했습니다. OP는 실제로 C++에서 발을 쏘기위한 목적으로 제공하는 정말로 비열한 총 중 하나를 발견 할 수있었습니다. – zwol
그리고 내 조언은 다음과 같습니다. 앞으로는 이해할 수없는 또 다른 문제가 생겨 도움을 요청할 때 가능한 한 가장 작은 프로그램으로 코드를 자르십시오. *는 동일한 오류를 생성합니다. 거의 항상 하나의 파일과 20 줄 미만으로 가져올 수 있습니다.이 과정에서 문제가 무엇인지 깨닫게 될지도 모릅니다. 그렇지 않은 경우에도 사람들이 여러분을 도울 수 있습니다. – zwol