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

  • Home
  • SEARCH
  • 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 9156965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:53:50+00:00 2026-06-17T12:53:50+00:00

I have a little problem while trying to implement a container, Set, based on

  • 0

I have a little problem while trying to implement a container, Set, based on a linked list.
Yeah, I know that there’s an STL implementation of a set, but this is for homework. 🙂

So, this is what I have done so far:

my Set.h file looks like that:

template <class T>
class Set {
private:
    typedef std::list<T> base_container;
    base_container items;
public:
    class myIterator {
    public:
        typename base_container::iterator base_iterator;
        myIterator() { }
    };
    void addItem(const T item) {
        items.push_back(item);
    }
    typedef typename Set<T>::myIterator setIterator;
    setIterator begin() { return items.begin(); }
    setIterator end() { return items.end(); }
    Set<T>(void) { }
    ~Set<T>(void) { }
};

Now, main.cpp:

#include "Set.h"

int main(void) {
    Set<int> mySet;

    mySet.addItem(1);
    mySet.addItem(2);
    mySet.addItem(3);
    mySet.addItem(4);

    Set<int>::myIterator x;
    x = mySet.begin();       // produces an error about non-convertible types.

    return EXIT_SUCCESS;
}

The error is as follows:

error C2664: 'Set<T>::myIterator::myIterator(const Set<T>::myIterator &)' : cannot convert parameter 1 from 'std::_List_iterator<_Mylist>' to 'const Set<T>::myIterator &' 

Clearly I messed things up, but I’m not sure which part of the code is actually the problem.
Any suggestions about how to fix this? Any helpful information will be appreciated.

Thanks. 🙂

  • 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-17T12:53:52+00:00Added an answer on June 17, 2026 at 12:53 pm

    There are many problems with your approach.

    As others have said, you can’t create your iterator type from the underlying type:

    setIterator begin() { return items.begin(); }
    setIterator end() { return items.end(); }
    

    This can be solved by adding a constructor to your type:

    class myIterator {
        typedef typename base_container::iterator base_iterator_type;
    public:
        explicit myIterator(base_iterator_type i) : base_iterator(i) { }
        base_iterator_type base_iterator;
        myIterator() { }
    };
    

    This constructor should be explicit, which means you need to change how you create it:

    setIterator begin() { return setIterator(items.begin()); }
    

    The next problem is that your type doesn’t implement the iterator interface, it doesn’t provide operator++ or operator* etc. and it doesn’t define nested types such as value_type and iteratory_category i.e. it’s not an iterator (just giving it a name with “iterator” in it doesn’t make it true!)

    Once you fix that and your type is a valid iterator, you’ll find your container can’t be used with STL-style algorithms because it doesn’t implement the container requirements. Among other things, it should provide a nested type called iterator not setIterator so that other template code can use S::iterator without caring if S is a std::set<T> or a Set<T>. Don’t call it Set<T>::setIterator, just call it Set<T>::iterator. Also in this case there’s no point defining myIterator (noone cares that it’s yours! 🙂 then having a typedef to call it setIterator, just name the type with the right name in the first place and you don’t need a typedef.

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

Sidebar

Related Questions

I have a little Problem with the app that I'm developing. In the App
I have a little problem with the library 'Telerik'. Indeed I want to implement
So, here is my little problem. Let's say I have a list of buckets
i have faced this problem couple of days ago, while trying to import an
I have a nagging problem that I have spent many hours trying to resolve
I have a little problem. I have developed a midlet application that call some
I have been trying to do a little project that needs an appendable ObjectOutputStream.
I have been looking for a little while for a solution to this problem,
I have little problem with a replacement of a little part in an url.
I have little problem in regular expressin creation. Expected input: blahblahblah, blahblahblah, 'blahblahblah', blahblahblah,

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.