1
私はC++で新しいです。私は、CPPにドラゴンオブジェクトを追加しようとしていますが、私は私がでエラーが発生しますプログラムのコンパイル時にオブジェクトC++で文字列とリストをマップに追加する
#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;
}
を追加しているときに私はエラーが発生します:
dmap.insert(dmaptype(location, dlist));
をし、誤りがあります:
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> > >&)
すべてのヘルプは
ありがとう...理解されるであろう
HIそれは同じエラーを与えます....プロジェクトの要件は、マップを使用して文字列としてキーを使用して、その中にドラゴンオブジェクトのリストを追加しようとすることです。 – Baba
あなたのリストをのリストに変更して、新しい、などを取り除いたのですか?リストはリストと同じではありません。 –
kfmfe04
申し訳ありません私の悪い...その問題を解決したおかげでヒープ – Baba