我有这个功能:
void plusQueue(){
PrioQueue<int> *a = new PrioQueue<int>(2);
PrioQueue<int> *b = new PrioQueue<int>(2);
a->push(3);
b->push(5);
a->push(7);
b->push(2);
cout << "a"<<endl;
a->print();
cout << "b"<<endl;
b->print();
cout<<"Samenvoegen\n";
PrioQueue<int> *c = new PrioQueue<int>(4);
c = a + b;
c->print();
}
而这一行:
c = a + b;
给出了一些问题。我收到这条消息:
main.cpp:71:13: error: invalid operands of types 'PrioQueue<int>*' and 'PrioQueue<int>*' to binary 'operator+'
这是我的模板类中的重载运算符:
PrioQueue operator +(PrioQueue a) {
PrioQueue temp = *this;
T *bottom = a.getBottom();
T *top = a.getTop();
for (T *element = bottom; element < top; element++) {
temp.push(*element);
}
return temp;
}
我在这里做错了什么?