Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8824777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:43:05+00:00 2026-06-14T06:43:05+00:00

I have the task to write own containers Linked_list and Array_list . I have

  • 0

I have the task to write own containers Linked_list and Array_list. I have one interface for them:

typedef int value_type;
class Container 
{
public:
        class Iterator 
        {   
        public:
            Iterator();
            Iterator(value_type* other);
            Iterator(const Iterator& other);
            Iterator& operator=(const Iterator& other);
                    ...
        };

    Container();
    Container(const Container& other);
    ~Container();   

    virtual value_type& front() const=0;
    virtual value_type& back() const=0;
    virtual Iterator begin() const=0; // 
    ...
};

I did derived classes Linked_list and Array_list:

class Linked_list:public Container 
{
public:
    long int cur_size;
    List elem;
    static Link end_;
    class Iterator: public Container::Iterator
    {
        friend Linked_list;
        Link *p;    
    };

    Iterator begin() const; //overriding virtual function return type differs ...

...
}

I thinks it’s all wrong. should nested class Linked_list::Iterator be a derived class?
Is it possible to do this, if I can’t change the interface?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:43:06+00:00Added an answer on June 14, 2026 at 6:43 am

    Taking into account your design constraints that you cannot use templates, than one thing should change: add interface IteratorImpl. Thus you can make class Iterator from base class Container non virtual. It needs to be non-virtual since STL-alike iterators should have value semantics. See pimpl idiom for more details how it works!

    Like this:

    typedef int value_type;
    class Container 
    {
        protected:
            class IteratorImpl
            {   
            public:
                virtual void next() = 0;
                virtual IteratorImpl* clone() const = 0;
                virtual value_type get() const = 0;
                virtual bool isEqual(const IteratorImpl& other) const = 0;
            };
    
        public:
            class Iterator 
            {   
            public:
                Iterator(IteratorImpl* impl) : impl(impl) {}
                ~Iterator() { delete impl; }
                Iterator(const Iterator& other) : impl(other.impl->clone()) {}
                Iterator& operator=(const Iterator& other) {
                  IteratorImpl* oldImpl = impl;
                  impl = other.impl->clone();
                  delete oldImpl;
                }
                bool operator == (const Iterator& other) const 
                {
                   return impl->isEqual(*other->impl);
                }
                Iterator& operator ++ ()
                {
                    impl->next();
                    return *this;
                }
                value_type& operator*() const 
                {
                   return impl->get();
                }
                value_type* operator->() const
                {
                   return &impl->get();
                }
            };
            Container();
            Container(const Container& other);
            ~Container();   
    
        virtual value_type& front() const=0;
        virtual value_type& back() const=0;
        virtual Iterator begin() const=0; // 
        ...
        };
    

    Then in your derived just implement IteratorImpl:

    class Linked_list:public Container 
    {
    protected:
        class IteratorImpl: public Container::IteratorImpl
        {
           ....
        };
    
    public:
        Iterator begin() const { return new IteratorImpl(firstNode); }
        Iterator end() const { return new IteratorImpl(nodeAfterLastNode); }
    
    ...
    };
    

    These firstNode and nodeAfterLastNode are just my guess – use whatever you need to implement the IteratorImpl interface…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a task where i need to write a multidimensional array to HDFS.
I have been assigned wit the task to write a program that takes a
I have question about XSLT1.0. The task is to write out in HTML all
I have very little knowledge about unix. My task is to write a shell
My task is keep expanded/collapsed groups during filter. I write own filter, which remove
I have to write program that create process using pipe() . My first task
I have been assigned a task where I am to emulate one of my
i have task which takes a parameter and has three modes of results Example
I have task involving reading SAS .xpt files using .NET. For that I'm using
I'm using dhtmlx Gantt Chart UI component which have task list and graphical chart.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.