Implementing class for disjoint sets C++的std ::地圖與用戶定義的數據類型
struct Set
{
int parent,rank;
Set(int i):parent(i),rank(0){}
Set(const Set& s2):parent(s2.parent),rank(s2.rank){}
};
struct Disjoint
{
std::map<int,Set> forest;
Disjoint(){}
void init_node(int i)
{
forest[i]=Set(i);//error here
}
};
Now after compiling it I see,
/usr/include/c++/4.7/bits/stl_map.h:458:錯誤:沒有匹配的功能()::
DU_SET.cpp:13:5:備註:候選人是:
DU_SET.cpp: :候選人期望1個支持者個nt,0提供
DU_SET.cpp:12:5:注意:設置::集(INT)
DU_SET.cpp:12:5:注:候選預計1個參數,0提供*
I have also implemented the copy constructor for class Set but the same error comes back again. when I implement another constructor with no parameters it works fine but why*
STL需要默認的構造函數.. – ikh
那麼,重複?http://stackoverflow.com/questions/695645/why-does-the-c-map-type-argument-require-an-empty-constructor-when-使用 –
說出'forest.insert(std :: make_pair(i,Set(i)))'。 –