#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");
}
这里是我的头文件的一部分:无法将参数3从'std :: vector <_Ty> *'转换为'Inventory *'。为什么?
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._Inv但也没有工作。
您正在使用[保留标识符](http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier)。你应该摆脱这种习惯。其他的挑战是'使用命名空间标准;''''system(“PAUSE”);',而'客户'的析构函数完全没有意义,因为矢量将要死去。 – chris 2012-08-04 04:22:03
您的编译器是否为该错误输出了一些行号?如果没有,你是否逐行删除,直到你确定了错误的行? – harper 2012-08-04 04:26:43