LinkedList의 생성자를 정수 배열로 초기화하려고 시도합니다.LinkedList가 배열을받을 생성자 C++
프로그램은 linked (array)를 호출합니다. 배열 내의 모든 값을 linkedlist에 추가합니다.
LinkedList::LinkedList(int array[])
{
headPtr->setData(array[0]); //setData method stores the integer at position 0 inside headPtr
Node *currentPtr = headPtr;
for (int i = 0; i < array.length(); ++i) //for loop to add the integers to the next node
{
currentPtr->setNext(new Node(array[i])); //creates a new node with the integer value of array position i
}
}
문제는 (자바에서 오는)이 사항 Array.length 내가 배열의 길이가이 방법을 얻을 수 있다고 생각하지 않는다?
재 : "자바에서 오는"- ** 정지 ** A [좋은 입문 C++ 책 (http://stackoverflow.com/questions/388242/the-definitive-c-book-을 선택하십시오. guide-and-list)를 읽고 그것을 통해 올바른 현대 C++를 배웁니다. C++은 Java가 아닙니다. C++로 프로그래밍 할 때 자바의 관점에서 생각하면 악몽 일뿐입니다. –
C- 배열의 길이를 얻을 수 없습니다 (C- 문자열과 같이 끝나지 않는 한). 예를 들어'std :: vector'에서 얻을 수 있습니다. –
@WTP : C-Array의 길이를 얻을 수 있습니다. 그러나 배열이 포인터로 감쇄 된 경우 길이를 얻을 수 없습니다. OP는 후자의 상황에 직면 해있다. – Nawaz