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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:23:56+00:00 2026-06-14T15:23:56+00:00

I have a STL map in C++ where the key is an unsigned int,

  • 0

I have a STL map in C++ where the key is an unsigned int, and the value is a class whose constructor is:

Foo::Foo(unsigned int integerValue){
    //Some stuff
}

At other class I have declarated the std::map at the header:

private:
    std::map<unsigned int, Foo> *m_mapFoo;

And at the cpp file I created it and inserted instances of Foo:

m_mapFoo = new std::map<unsigned int, Foo>;
m_mapFoo->insert(0, new Foo(0));
m_mapFoo->insert(1, new Foo(1));

But I’m getting the following error at the insert methods:

no matching function for call to ‘std::map<unsigned int, Foo, std::less<unsigned int>, std::allocator<std::pair<const unsigned int, Foo> > >::insert(const unsigned int&, Foo*)’

Similar problem at find method:

m_mapFoo.find(0)->second->someFunctionIntoFooClass();

Where the error is exactly the following:

request for member ‘find’ in ‘((Foo*)this)->Foo::m_mapGeoDataProcess’, which is of non-class type ‘std::map<unsigned int, Foo, std::less<unsigned int>, std::allocator<std::pair<const unsigned int, Foo> > >*’

Additional notes: I don’t have a Foo copy constructor, but I don’t think that’s the problem.

Any help understanding this errors?

  • 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-14T15:23:58+00:00Added an answer on June 14, 2026 at 3:23 pm

    You have a pointer to a map containing Foo values

    std::map<unsigned int, Foo> *m_mapFoo;
    

    and you are treating it as if it contained Foo pointer values:

    std::map<unsigned int, Foo*> *m_mapFoo;
    

    Try this:

    m_mapFoo = new std::map<unsigned int, Foo>;
    m_mapFoo->insert(std::make_pair(0, Foo(0)));
    m_mapFoo->insert(std::make_pair(1, Foo(1)));
    

    As for the second error, you have a pointer to a map, so you need

    std::map<unsigned int, Foo>::iterator it = m_mapFoo->find(0);
    if (it) {
      it->second.someFunctionIntoFooClass();
    } else {
      // entry not found
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have to use stl map containing 3 values : float(key) , int ,int.
If i have a stl map from string to int and i want to
How can I implement STL map sorting by value? For example, I have a
I have a vector containing objects of type STL map, and I do vector.push_back(some
I'm trying to create a map whose key and value are both structs (stE
Suppose I have: stl::map<std::string, Foo> myMap; is the following function thread safe? myMap[xyz] ?
I have a stl::map which key type is a custom struct. I want to
Map type from STL have next type: std::map< Key, Data, Compare, Alloc > As
Suppose I have a STL map where the values are pointers, and I want
I have a stl::list containing Widget class objects. They need to be sorted according

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.