C++ 无法对商店进行盘点
Store.cpp:C++ 无法对商店进行盘点,c++,vector,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 可查找。h: private: T *aptr[MAXRANGE]; int rangeStart[MAXRANGE]; i
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
可查找。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;
}
问题是当指针返回时,它无法为产品对象分配地址。无法理解您的问题我正在尝试返回指针,然后分配产品对象。但调试后,显示指针/表[plu_code]中没有对象字段