我遇到错误读取,从“int”转换为“TrashCan”的功能样式没有匹配的转换。
这是标题中的声明:
class TrashCan
{
friend TrashCan operator +( TrashCan& left,
TrashCan& right);
public:
TrashCan();
int size=0;
int item=0;
void setSize(int);
void addItem();
这是我的实现:
TrashCan operator +(const TrashCan& left,
const TrashCan& right) {
TrashCan t= TrashCan( left.size + right.size );
return( t );
}
这是底部带有运算符的主要内容:
int main( ) {
cout << "Welcome to My TrashCan Program!" << endl;
TrashCan myCan;
TrashCan yourCan;
yourCan.setSize( 12 );
myCan.setSize( 12 );
yourCan.addItem( );
yourCan.addItem( );
myCan.addItem( );
myCan.printCan();
yourCan.printCan();
//TrashCan combined = yourCan + myCan;