연결된 목록을 사용할 때 딥 복사를 수행하는 데 많은 어려움이 있습니다. 나는 꽤 문제가 otherList.listData->를 사용하는 것이 나에게 값을 복사하는 것이 아니라 원래의리스트에있는 데이터에 대한 포인터를주는 것이라고 확신한다. 그러나 나는 그 데이터에 직접적으로 어떻게 접근 할 수 있는지에 대해 당황 스럽다. 나는 당신이 그 포인터를 derefence 수 있다고 생각했지만 그 구문에 대한 잘못된 구문이 있어야합니다. CourseList 클래스에서 필요로하는 데이터에 대한 get/set 메서드도 없습니다.연결된 목록이있는 Ctor 복사
아무도 아이디어가 있습니까 ???
헤더 파일
class CourseList
{
private:
struct CourseNode
{
int CRN;
char letterGrade;
CourseNode *next;
};
int length;
CourseNode *listData;
public:
CourseList();
CourseList(const CourseList& otherList);
~CourseList();
};
CPP
CourseList::CourseList(const CourseList& otherList)
{
length = otherList.length;
for (int i = 0; i < length; i++)
{
CourseNode* temp = new CourseNode;
temp->CRN = otherList.listData->CRN;
temp->letterGrade = otherList.listData->letterGrade;
temp->next = otherList.listData->next;
listData = temp;
}
}
당신이 [이 뭔가를 (할 노력하고 확신 http://ideone.com/ :
대신에, 당신은 당신의 반복, 즉, 이런 일에 그 설정해야합니다 JcFPfR). – WhozCraig