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 7559561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:40:08+00:00 2026-05-30T12:40:08+00:00

I’m a new C++ programmer, I learned Java and ANSI C a time ago

  • 0

I’m a new C++ programmer, I learned Java and ANSI C a time ago and decided to give it a shot.

Well, I love C++, but I didn’t like how the iterators work:

In java, you could make a whole container private and implement a getter function to it’s iterator, and the iterator has a method hasNext() that returns a boolean depending on if it has reached the end of the container.

The only way I found to do something similar on C++ is writing 2 getters, iteratorBegin() and iteratorEnd(), that returned an interator corresponding to the first and last positions, incrementing the iterator returned by iteratorBegin() and comparing it with iteratorEnd(), allowed me to iterate over the container until the final position had been reached

But, I want to use only ONE getter method, and I thought: “Let’s make my own iterator class”

So far so good, I’ve done it successfully with sets and lists, but I can’t seem to make it with maps, here’s the code that’s troubling me: (the class is defined in a separate .h, this is called customIterator.cpp)

template<typename T, typename D>
const D& custIterator<T,D>::next()
{
    const D& obj = (*it);
    if(hasNext())
    {
        it++;
    }
    return obj;
}

//the above works fine

template<typename T, typename D>
const D& custIterator<map<T,D>,D>::next() //error in this line
{
    D& obj = (*it).second; 
    if(hasNext())
    {
        it++;
    }
    return obj;
}

when compiling the specialized method, it says: error: ‘map’ was not declared in this scope
even though I added #include <map> on top of the file

I’m using gcc version 4.4.5 (Debian 4.4.5-8) with codeblocks

Please, I need some assistance.

Thanks for your attention!

  • 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-05-30T12:40:10+00:00Added an answer on May 30, 2026 at 12:40 pm

    All the standard containers are inside the namespace std, you should qualify it thus

    std::map<T,D>
    

    In general I would recommend not trying to carry over Java idioms to C++ since each language has its own idioms and mixing them will confuse other programmers (just as I think that #define BEGIN { isn’t the best idea ever).

    What you’re trying to do is known as ranges and is considered by some to be a better solution than C++ iterators but until it makes its way into the language I think it’s harmful for each developer to invent their own ranges.

    Further reading or tl;dr slides (there’s a video to go with this which I can’t find at the moment).

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I

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.