2
我越來越錯誤,如果任何人有任何想法,請幫助我。錯誤:錯誤C2663:'std :: _樹<_Traits> ::插入':2重載沒有合法的轉換爲'這個'指針
我得到這個錯誤void traverse
功能,我已經使用insert
功能插入地圖。
struct node {
int weight;
unsigned char value;
const node *child0;
const node *child1;
map<unsigned char, string> huffmanTable;
node(unsigned char c = 0, int i = -1) {
value = c;
weight = i;
child0 = 0;
child1 = 0;
}
node(const node* c0, const node *c1) {
value = 0;
weight = c0->weight + c1->weight;
child0 = c0;
child1 = c1;
}
bool operator<(const node &a) const {
return weight >a.weight;
}
void traverse(ostream& o,string code="") const {
if (child0) {
child0->traverse(o, code + '0');
child1->traverse(o, code + '1');
} else {
o<<value<<"\t";
cout <<" " <<value <<" ";
o<<weight<<"\t";
cout <<weight;
o<<code<<endl;
cout <<" " <<code <<endl;
huffmanTable.insert(pair<unsigned char, std::string>(value,code));
}
}
};
你救了我很多時間。謝謝 – Rajul 2012-07-22 16:17:32
@Rajul我希望你沒有讓變量'mutable'。我傾向於低估這個答案只是爲了表明這一點。 – 2012-07-22 16:22:04
@Luchian我已經從功能中刪除了const – Rajul 2012-07-22 16:41:12