C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 10th, 2005, 12:00 AM
wingz198 wingz198 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 1 wingz198 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 42 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old September 12th, 2005, 06:25 AM
MichaelSoft MichaelSoft is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: The Netherlands
Posts: 121 MichaelSoft User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 20 sec
Reputation Power: 4
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);
};

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Need some help with lists


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT