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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:20:59+00:00 2026-06-08T14:20:59+00:00

I hit some behaviour I can’t seem to wrap my head around. Say I

  • 0

I hit some behaviour I can’t seem to wrap my head around. Say I have a class defined as follows (a simple example for illustration):

class some_class
{
   public:
        some_class()
        {
            x_["0"] = "0";
            x_["1"] = "1";

            y_[0] = x_.find("0");
            y_[1] = x_.find("1");
        }

        int some_function(int i)
        {
            if(std::find(y_.begin(), y_.end(), x_.find("1")) != y_.end())
            {
                std::cout << "Found!" << std::endl;

                return 1001;
            }

            return -1001;
        }

   private:
       std::unordered_map<string, string> x_;
       std::array<unordered_map<string, string>::iterator, 2> y_;
};

The code compiles with Visual Studio 2012 RC in debug mode (others modes not tested), but during call to some_function the program fails with a following assertion message

… microsoft visual studio 11.0\vc\include\list Line: 289

Expression: list iterators incompatible…

The calling code looks like this

auto vector<int> as;
as.push_back(1);   

auto vector<int> bs;   
auto some = some_class();

std::transform(as.begin(), as.end(), std::inserter(bs, bs.begin()), [=](int i) { return  some.some_function(i); });

Question:

What would be the problem with this kind of an arrangement? I get the code run fine if I declare x_ and y_ in some_function instead of as member variables. The class is being called/used in std::transform like occasions, if that should factored in to the situation.

As a tangential aside, it looks like the following declaration will be rejected by the compiler, should it be rejected?

std::unordered_map<string, string> x_;
std::array<decltype(x_.begin()), 2> y_;

The error message is

error C2228: left of ‘.begin’ must have class/struct/union

  • 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-08T14:21:01+00:00Added an answer on June 8, 2026 at 2:21 pm

    Your situation.

    #include <unordered_map>
    #include <array>
    #include <iostream>
    #include <string>
    
    class some_class
    {
       public:
            some_class()
            {
                x_["0"] = "0";
                x_["1"] = "1";
    
                y_[0] = x_.find("0");
                y_[1] = x_.find("1");
            }
    
            int some_function()
            {
                if(std::find(y_.begin(), y_.end(), x_.find("1")) != y_.end())
                {
                    std::cout << "Found!" << std::endl;
    
                    return 1001;
                }
    
                return -1001;
            }
    
       private:
           std::unordered_map<std::string, std::string> x_;
           std::array<std::unordered_map<std::string, std::string>::iterator, 2> y_;
    };
    
    void function(some_class cl)
    {
        cl.some_function();
    }
    
    int main()
    {
        some_class c;
        function(c);
    }
    

    Your iterators points on elements of another map, that stored in this after copy-ctor, and in find there is comparison.

        bool operator==(const _Myiter& _Right) const
            {   // test for iterator equality
     #if _ITERATOR_DEBUG_LEVEL == 2
            if (this->_Getcont() == 0
                || this->_Getcont() != _Right._Getcont())
                {   // report error
                _DEBUG_ERROR("list iterators incompatible");
                _SCL_SECURE_INVALID_ARGUMENT;
                }
    

    for decltype –

    std::unordered_map<string, string> x_;
    std::array<decltype(x_.begin()), 2> y_;
    

    incorrect in class-block, since there is no object. This will works if x_ will be static.

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

Sidebar

Related Questions

I am working though some simple DX tutorials, and have hit an early snag.
I'm onto problem 245 now but have hit some problems. I've done some work
I have hit a real problem. I need to do some Kmeans clustering for
I was just poking around into some new stuff in C++0x, when I hit
Having some odd behavior I'd love some feed back on as I can't seem
I have hit a wall and have been pulling my hair for quite some
So I hit some weird combination of keystrokes, and now my visual studio looks
I've been a pretty long time PHP developer, and I'm starting to hit some
Presumably there's some tiny performance hit, but beyond that?
Some web apps 'by design ' don't function well when user's hit the back

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.