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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:01:38+00:00 2026-05-27T03:01:38+00:00

This is my CreateCustomer method: CustomerData Database::createCustomer(std::string const& name) { CustomerData data(customersDb.size()+1, name); customersDb[data.number()]

  • 0

This is my CreateCustomer method:

CustomerData Database::createCustomer(std::string const& name) {
    CustomerData data(customersDb.size()+1, name);
    customersDb[data.number()] = data;
//    customersDb.insert(std::pair<uint, CustomerData>(data.number(), data));
    return data;
}

Constructor of class CustomerData:

CustomerData::CustomerData(uint number, std::string const& name) {
    m_number = number;
    m_name = name;
}

Incorrect line is this one:

customersDb[data.number()] = data;

Thing is, the next line works. I can’t figure it out and can’t use insert because accessing element with [] brackets doesn’t work either.

I’ve tried even creating copy constructor but with no effect:

CustomerData::CustomerData(CustomerData &data) {
    m_number = data.number();
    m_name = data.name();
}

These are the errors:

Database.cpp:5: instantiated from here
stl_map.h:450: error: no matching function for call to 'CustomerData::CustomerData()'
CustomerData.h:18: candidates are: CustomerData::CustomerData(CustomerData&)
CustomerData.h:17: note: CustomerData::CustomerData(uint, const std::string&)

I use Mingw.

  • 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-27T03:01:39+00:00Added an answer on May 27, 2026 at 3:01 am

    operator[] with the standard map template default-constructs an element with the given key if none already exists.

    Your element type has no default constructor, so this cannot happen.

    You’ll have to use .insert instead.

    customersDb.insert(make_pair(data.number(), data));
    

    I can’t figure it out and can’t use insert because accessing element with [] brackets doesn’t work either.

    To modify an existing element, retrieve an iterator with .find, dereference and do your thing.

    yourMapType::iterator it = customersDb.find(data.number());
    if (it != customersDb.end())
       *it = data;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's imagine I have a Service method which creates a customer: public Customer CreateCustomer(string
This is my first attempts at creating a data-mart/warehouse and I am a little
This is my code: $.ajax({ url: someUrl, type: PUT, data: { id: id, message:
Apologies in advance for the length of this question! I have a data structure
This is my database table. Now I want to combine Branch_Id, Acc_no and Acc_Type
This is a bit of a long shot, but if anyone can figure it
This is starting to vex me. I recently decided to clear out my FTP,
This is kinda oddball, but I was poking around with the GNU assembler today
This might seem like a stupid question I admit. But I'm in a small
This is a difficult and open-ended question I know, but I thought I'd throw

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.