class jctree
{
public:
jctree(string na, bool is, int res, int co = 0) :name(na), is_leaf(is), result(res) ,count(co)
{}
string name;
jctree operator = (jctree& jc)
{
jctree c(jc.name, jc.is_leaf, jc.result,jc.count);
c.jclist = jc.jclist;
return c;
}
map<int, jctree>jclist;
int count;
bool is_leaf;
int result;
jctree& addattr(int attr, jctree& jc)
{
jclist.insert(make_pair(attr,jc));
count++;
return *this;
}
};
for (auto i = jc.jclist.begin(); i != jc.jclist.end()&&idex>=0; i++)
{
if (a[idex] == i->first)
{
jctree jj(i->second);
jc = jj;
break;
}
}
这里如果不用 jj保存i->second的结果,而直接复制给jc将引发错误。
’因为i->second是 jc里面的jclist的内容,自己的一部分,赋值给自己将引发错误。