| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need some help with lists
Hi, I'm having problems setting this up. I've completely forgotten how to do this. What I'm looking to do is make a list of arrays, but can't remember how to initialize it in the constructor in the header file.
Here's my code from it and I've bolded the part I'm having trouble with: Code:
class List
{
private:
class Node
{
public:
int data[12];
int pos;
Node * next;
Node (int [] d = [], Node * n = NULL)
:data(d), next(n) {};
};
Node * head;
public:
List() {head = new Node();}
void insert (int i);
void remove (int i);
bool find (int i);
};
Thanks in advance for any help |
|
#2
|
|||
|
|||
|
I would solve it like this:
Code:
class Node
{
public:
int data[12];
int pos;
Node * next;
Node(Node * n = NULL) // Default constructor
:next(n)
{
memset(data, 0, 12*sizeof(int));
};
Node (int d[12], Node * n = NULL) // Constructor taking an array
:next(n)
{
if(d)
{
memcpy(data, p, 12*sizeof(int));
}
};
};
class List
{
private:
Node * head;
public:
List() {head = new Node();} // Call the default constructor
void insert (int i);
void remove (int i);
bool find (int i);
};
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Need some help with lists |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|