CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 18

Threaded View

  1. #1
    Join Date
    Mar 2009
    Location
    Riga, Latvia
    Posts
    128

    general purpose Singly-linked list implementation with inheritance

    The challenge is to implement a general purpose Singly-linked list.

    I've found a good decision with templates, it looks natural and works good, but it's too long to write something like list->get_node()->get_data()->get_some_stuff()->set_value(value), when number of fields is more than one, and I have to add class or structure to a node. So class template is not the thing i'm searching for.

    Particularly, I want to incorporate new fields to a node witch is an inner class of a Slist class.
    But I'm stuck with syntax

    Here is my code:


    class Slist
    {
    private:
    class Node; // just enough for a node
    class Sentinel; // sentinel node, no data fields

    protected:
    class Data; // data node, opened for inheritance - ???

    private:
    Sentinel *first_node;
    Node *last_node;
    };



    class Slist::Node
    {
    public:
    // trivial interface stuff
    private:
    Node *next_node;
    };

    class Slist::Sentinel : public Slist::Node
    {
    // it seems, that's all
    };

    class Slist:ata : public Slist::Node
    {
    // that's all, but only for some time
    };

    That is to say, I want to inherit Slist and add fields to it's inner class Data
    How it could be done?

    P.S.: What will happen in such an erroneous case:
    ((Node *)(first_node/*Remenber, It's Sentinel*/))->call_some_interface_method_of_Data_class()
    ?
    Last edited by andrey_zh; March 17th, 2009 at 09:41 AM. Reason: ambiguous wording of the things to do and not to do

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured