Hi I'm a beginner at c++ and I'm having trouble solving this issue. I have a linkedlist of nodes and the node contains data of int array and a pointer pointing to the next node.
struct node {
unsigned int numbers[6];
node* next;
};
I also have a class:
private:
ticket* ticketListHead;
ticket* ticketListTail;
and in a public method:
public:
void newNode() {
int arr[6];
for(int i = 0; i < 6; ++i) {
arr[i] = ( std::rand() % 49 ) + 1;
}
node *temp = new node;
temp->numbers=arr;
temp->next=NULL;
}
The problem I believe is with the temp->numbers=arr line as I believe arrays cannot be assigned like that in C++. I'm not sure how to solve the problem in this case and I've tried looking online. Some help would be appreciated!
std::array? - NathanOliverrand()is highly problematic and you’re strongly encouraged to use an appropriate random number generator facility in the Standard Library that produces high-quality random values. Your use oftime(NULL)as a random number seed means that this will produce identical results if run in the same second, and on many platformsrand()is barely random at all. - tadmannewNode(), and write directly totemp->numbers[i]rather thanarr[i]. - HolyBlackCatnodehave a constructor? It probably should to avoid initializing it incorrectly or forgetting to populatenextand such. - tadman