Это мой классAppend не будет работать в Linked Список массивов в C++
class NumberList
{
private:
// Declare a structure for the list
struct ListNode
{
double value[10]; // The value in this node
struct ListNode *next; // To point to the next node
};
ListNode *head; // List head pointer
public:
// Constructor
NumberList()
{ head = nullptr; }
// Destructor
~NumberList();
// Linked list operations
void appendNode(double []);
void insertNode(double []);
void deleteNode(double []);
void displayList() const;
};
Это моя функция Append и я не могу заставить его работать - я получаю сообщение об ошибке.
void NumberList::appendNode(double num[])
{
ListNode *newNode; // To point to a new node
ListNode *nodePtr; // To move through the list
// Allocate a new node and store num there.
newNode = new ListNode;
newNode->value = num;
newNode->next = nullptr;
// If there are no nodes in the list
// make newNode the first node.
if (!head)
head = newNode;
else // Otherwise, insert newNode at end.
{
// Initialize nodePtr to head of list.
nodePtr = head;
// Find the last node in the list.
while (nodePtr->next)
nodePtr = nodePtr->next;
// Insert newNode as the last node.
nodePtr->next = newNode;
}
}
Сообщение об ошибке:
prog.cpp: In member function ‘void NumberList::appendNode(double*)’: prog.cpp:40:19: error: incompatible types in assignment of ‘double*’ to ‘double [10]’ newNode->value = num;
Любые предложения о том, что я делаю неправильно?
Я думаю, вы хотите поставить & перед значением newnode-> или сделать это как & newnode-> значение [0], но прошло некоторое время, так как я работал с C++. – gmlacrosse