Nécessité Constructeur sans arg et container MAP
Bonjour,
J'ai une question pour laquelle je cherche une explication exacte:
Situation du problème (cas d'école):
J'ai deux classes, l'une "point "avec 2 données membres et un constructeur avec 2 paramètres, et l'autre "MapPoint" ayant un container MAP (Key=int et value=un objet point) et donc une fonction membre pour inserer un nouveau point à la cle Index.
J'ai donc comme argument de ma fonction InsertPoint un entier et un point.
Le probleme est le suivant:
si je ne définit pas un constructeur sans argument (ou argument par défaut) j'ai une erreur de compilation du sytle:
Citation:
[C++ Error] _map.h(162): E2285 Could not find a match for 'point::point()'
[C++ Error] _map.h(162): E2285 Could not find a match for 'pair<const int,point>::pair(const int,undefined)'
[C++ Error] _map.h(162): E2285 Could not find a match for 'map<int,point,less<int>,allocator<pair<const int,point> > >::insert(_Rb_tree_iterator<pair<const int,point>,_Nonconst_traits<pair<const int,point> > >,undefined)'
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
class point{
int x,y;
public:
// point(){};
point(int,int);
point(const point &);
friend bool operator < (const point &,const point &);
};
class MapPoint{
std::map<int,point> MapPt;
public:
void InsertPoint(int,point);
point operator[](int);
};
//----------------------------------------------------
point::point(int abs,int ord){x=abs;y=ord;}
point::point(const point & pt)
{
x=pt.x;
y=pt.y;
}
bool operator < (const point & pt1,const point & pt2)
{
return(pt1.x<pt2.x);
}
void MapPoint::InsertPoint(int Index,point Pt)
{
MapPt.insert(make_pair(Index, Pt));
}
point MapPoint::operator[](int Index)
{
return MapPt[Index];
} |
Je suppose donc que lors d'une insertion d'un objet dans un container MAP, il se produit d'abord uns instanciation de la class point par l'appel au constructeur point::point() et puis recopie des valeurs grâce à l'opérateur = par défaut?? Est-ce juste?
Merci