0
#include "foodservice.h"
#include <iostream>
using namespace std;

int main() {
  Inventory Master;
  bool flag;
  Customer Bob("Bob", 12345, 100.00 );
  Customer Joe("Joe", 56789, 50.00 );
  Customer Arjun("Arjun", 98765, 00.01 );
  Customer Randy("Randy", 54689, 30.28);
  Customer Mark("Mark", 76598, 15.18);


  Master.firststock( "inventory.txt" );
  vector<Food> temp = Master._Inv;
  for(unsigned int i=0; i<temp.size(); i++ ) {
    cout << temp[i].name << " " << temp[i].quant << " " << temp[i].price << endl;
  }

  flag = Bob.addCart( "Apple" , 10,  &Master._Inv );
  Bob.report();
  flag = Bob.addCart( "Oranges", 2, &Master._Inv );
  flag = Bob.removeCart( "Apple", 3, &Master._Inv );
  flag = Arjun.addCart( "Apple", 1, &Master._Inv );
  flag = Bob.checkout(&Master._Inv);
  flag = Arjun.checkout(&Master._Inv);
  Master.summary();*/



  system("pause");

}

这是我的头文件的一部分:

class Inventory;
class Customer {
  public:
    Customer(string n, int c, double b );
    ~Customer() { _Cart.clear(); };
    bool addCart( string name, int q, Inventory* inv );
    bool removeCart( Food f, int q, Inventory* inv );
    void report(); 
    bool checkout(Inventory* inv); 
  protected:
    string name;
    int card;
    double balance;
    CreditCard _CC(int c,double b);
    vector<Food> _Cart;
};


The error i am getting is: cannot convert parameter 3 from 'std::vector<_Ty> *' to 'Inventory *'
1>          with
1>          [
1>              _Ty=Food
1>          ]
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

我很感激帮助。所以当我使用 &Master._Inv 时会显示错误。_Inv 是我在标题中其他地方声明但未包含的食物向量。然而问题出在指针 &Master.... 我也试过 *Master._Inv 但也没有工作。

4

2 回答 2

3

错误消息非常简单。 addCart, removeCart, 并且checkout都将指针Inventory作为参数。但是您的论点&Master._Inv是指向 a 的指针std::vector<Food>。也许你的意思只是&Master

于 2012-08-04T04:26:34.707 回答
2

Customer::addCart() 的第三个参数是一个指向 Inventory 对象的指针。尝试通过它&大师。

于 2012-08-04T04:26:46.233 回答