无法对商店进行盘点

时间:2014-11-29 05:23:43

标签: c++ vector

Store.cpp:

table[plu_code] = new Product(plu_code, name, sold_by_weight, price, inv);//This will call look up table operator '[]'
num_products++; // counting number of items in inventory

LookupTable.h:

private:
T *aptr[MAXRANGE];
int rangeStart[MAXRANGE];
int rangeEnd[MAXRANGE];
int numRanges;
T defaultValue; //needed to return when [] operator does not find valid product


T &LookupTable<T>::operator[](int value)
{ 
// find the range
if (value>0 && value<9999) //inorganic tems
    return aptr[0][value-rangeStart[0]];
else if (value>90000 && value<99999)//organic items
    return aptr[1][value - rangeStart[1]];
else
    return defaultValue;
}

问题是当返回指针时,它无法为产品对象分配地址。enter image description here

0 个答案:

没有答案