item.h
来自「vc实现的0-1背包问题」· C头文件 代码 · 共 58 行
H
58 行
//////////////////////////////////////////////////////////////////////////
//
// Item.h
//
//////////////////////////////////////////////////////////////////////////
#ifndef ITEM_H_H
#define ITEM_H_H
#include "CustomizedTypes.h"
#include <FSTREAM>
using namespace std;
template <class TProfit, class TWeight>
class Item
{
public:
Item(TProfit p = 0, TWeight w = 0): m_profit(p), m_weight(w) {}; //constructor
Item(const Item<TProfit, TWeight>& aItem) { //copy constructor
m_profit = aItem.GetProfit();
m_weight = aItem.GetWeight();
}
TProfit GetProfit() const {
return m_profit;
}
void SetProfit(TProfit p) {
m_profit = p;
}
TWeight GetWeight() const {
return m_weight;
}
void SetWeight(TWeight w) {
m_weight = w;
}
operator = (const Item<TProfit, TWeight>& item) { //重载赋值运算符
m_profit = item.GetProfit();
m_weight = item.GetWeight();
}
friend ofstream& operator << (ofstream& out, const Item<TProfit, TWeight>& item) { //重载"<<"运算符
out<<"("<<item.GetProfit()<<","<<item.GetWeight()<<")";
return out;
}
private:
TProfit m_profit;
TWeight m_weight;
};
#endif //ITEM_H_H
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?