链表重载等号_c ++链表运算符重载

本篇博客讨论了C++中操作符重载的问题,特别是如何实现两个Bag类实例之间的减法运算。作者分享了相关的源代码,并请求帮助理解如何正确地重载操作符以实现特定的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Links to my code, did not use the code tags here because there are a lot of files... The links are in c++ syntax. This is my first post.

node.h

http://pastebin.com/3jrnNN5p

main.cpp

http://pastebin.com/LAa1tpi2

node.cpp

http://pastebin.com/GxYmne1L

bag.cpp

http://pastebin.com/Zup91snh

bag.h

http://pastebin.com/evdxtSx8

I have all of these files for my c++ homework and I am having trouble overloading the - and -= operators to use in my bags x and y. The homework states that we must do it like this;

For two bags x and y. The bag x-y contains all the items of x, with any items from y removed. For example, suppose that x has seven copies of the number 3, and y has two copies of the number 3 (ie 7-2 copies of the number 3). In the case where y has more copies of an item than x does, the bag x-y will have no copies of that item. The statement x -= y should have the same effect as the assignment x = x-y.

Does anyone know how this would be done? Maybe some examples using my code? Thanks, I do not wish for you to write the 2 overloading functions for me. If you are willing then by all means go ahead, but if you do try to explain it to me.

解决方案It looks like you did not really got to the idea of the value of home assignment, not yet. Here is a hint for your: home assignments are very valuable. If you have to pay for education, please understand: this is perhaps most valuable part of your school activity worth paying for. If you do not do your home assignment 100% by yourself, this is the same as flushing money down the toiled. And you don''t want it.

So, I suggest we give you another chance to use the opportunities your school gives you.

Good luck,

—SA

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值