#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
我很感激帮助。因此,当我使用&amp; Master._Inv时,错误显示出来。 _Inv是食物的载体,我在标题中的其他地方声明但未包括在内。然而问题出在指针和Master ......我也试过* Master._Inv但是也没用。
答案 0 :(得分:3)
错误消息非常简单。 addCart
,removeCart
和checkout
都指向Inventory
作为参数。但是您的参数&Master._Inv
是指向std::vector<Food>
的指针。也许你的意思是&Master
?
答案 1 :(得分:2)
Customer :: addCart()的第三个参数是一个指向Inventory对象的指针。尝试传递它和Master。