I am creating a custom Node class that holds a number and a pointer to another node. I am writing a function called AssignArray which takes an array and creates a linked list of nodes from the numbers in the array. I am passing an array to the AssignArray function, and need to remove the first element from the array with each new recursive call of the function. I am trying to do that by copying the initial array into a smaller array, and then passing the smaller array into the recursive call of the AssignArray function. I am getting an error when I try to copy the array. Here is my .hpp file:
class Node {
Node* node;
int num;
public:
Node(int new_num);
void AssignNode(Node* new_end);
Node* AssignArray(int list[]);
};
Here is my node class file:
#include <iostream>
#include "node.hpp"
Node::Node(int new_num) {
num = new_num;
}
void Node::AssignNode(Node* new_node) {
node = new_node;
}
Node* Node::AssignArray(int list[]) {
if (sizeof(list) == 0) {
return 0;
}
else {
Node new_node(list[0]);
int new_list[sizeof(list)-1];
std::copy(1, std::end(list), std::begin(new_list));
new_node.AssignNode(new_node.AssignArray(new_list));
return &new_node;
}
}
My IDE gives me an error which says "No instance of overloaded function "std::end" matches the argument list -- argument types are (int *)
Thanks in advance for the help!