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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:32:23+00:00 2026-05-29T12:32:23+00:00

I am new in c++. I am trying to add a dragon object in

  • 0

I am new in c++. I am trying to add a dragon object in cpp but i am receiving an error while adding the object

#include "dragon.h"
using std::cin;
#include <map>
using std::map;
#include <list>
#include <string>
#include <iostream>
using namespace std;
using std::list;

typedef map<string,list<Dragon> >::iterator iter;
typedef map<const string,list<Dragon> >::value_type dmaptype;
void display(map<string,list<Dragon> > dmap1,iter dmapiter1);


int main( )
{
  map<string,list<Dragon> >dmap;
iter dmapiter;

bool again = true;

string name;
double length;
string colour;
string location;
while( again )
{
     // get the details for the dragon
     cout << "\nEnter dragon name >> ";
     getline( cin, name );

     cout << "\nEnter dragon length >> ";
     cin >> length;

     cin.get( );

     cout << "\nEnter dragon colour >> ";
     getline( cin, colour );

     // now get the location
     cout << "\nEnter location >> ";
     getline( cin, location );
     dmapiter=dmap.find(location);

    Dragon * ptr ;
    ptr=new Dragon(name,length,colour);

     if(dmapiter==dmap.end())
     {
        list<Dragon*> dlist;
        dlist.push_back(ptr);
        dmap.insert(dmaptype(location, dlist));
     }
     else
     {
        dmapiter->second.push_back(*ptr);
     }
     char choice;

     cout << "\nEnter another dragon and location [ y / n ] ? ";
     cin >> choice;
     cin.get( );
     if( choice != 'y' && choice != 'Y' )
     {
          again = false;
     }

}
 display(dmap,dmapiter);


cout << endl;

return 0;


}

when i compile the program i am receiving an error at:

dmap.insert(dmaptype(location, dlist));

and the error is :

 error: no matching function for call to ‘std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::list<Dragon, std::allocator<Dragon> > >::pair(std::string&, std::list<Dragon*, std::allocator<Dragon*> >&)’
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_pair.h:83: note: candidates are: std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _T2 = std::list<Dragon, std::allocator<Dragon> >]
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_pair.h:79: note:                 std::pair<_T1, _T2>::pair() [with _T1 = const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _T2 = std::list<Dragon, std::allocator<Dragon> >]
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_pair.h:68: note:                 std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::list<Dragon, std::allocator<Dragon> > >::pair(const std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::list<Dragon, std::allocator<Dragon> > >&)

Any help will be appreciated…

Thank you

  • 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-29T12:32:25+00:00Added an answer on May 29, 2026 at 12:32 pm

    Try:

    dmap.insert(std::make_pair(location, dlist));
    

    but you also need to make the type of dlist consistent with that of your map – use list<Dragon> or list<Dragon*> for both.

    For simplicity (so you don’t need to worry about deleting), try list<Dragon> first.
    When you insert into this list, a copy will be made (since STL has value-semantics), so it’s ok if you create a Dragon locally on the stack to insert into dlist. (You can think of it as a copy being made: copy elision may occur if the compiler is smart, but don’t worry about that, for now).

    For example:

    Dragon dragon(name,length,colour);
    
    if(dmapiter==dmap.end())
    {
      list<Dragon> dlist;
      dlist.push_back(dragon);
      dmap.insert(make_pair(location, dlist));
    }
    else
    {
      dmapiter->second.push_back(dragon);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im new to asp.net mvc. I'm trying add new model class but it got
I am trying to add a new column into an SQLiteDatabase but every time
Trying to add a new element to the DOM but I get all sorts
I am trying to add new document in the solr server using ajax. To
I am trying to add a new column in a GridView but it doesn't
I'm trying to add new entries to an sql database using php, i can
I'm trying to add new object to my ArrayList if it satisfy the condition.
I'm trying to add a new row to a DataGridView from FORM 2 but
Hi I am trying to add new workitems to the TFS repository using the
i'm new to django and im trying add a user using django admin page.

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.