简体   繁体   中英

cannot convert parameter 3 from 'std::vector<_Ty> *' to 'Inventory *'. Why?

#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");

}

here is PART OF my header file:

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

I could appreciate the help. so the error is showing when i am using &Master._Inv. _Inv is a vector of food i declared somewhere else in my header but have not included. However the problem is with the pointer &Master.... i also tried *Master._Inv but did not work either.

The error message is pretty straightforward. addCart , removeCart , and checkout all take a pointer to Inventory as a parameter. But your argument &Master._Inv is a pointer to a std::vector<Food> . Maybe you meant just &Master ?

The third parameter to Customer::addCart() is a pointer to an Inventory object. Try passing it &Master.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM