2012-08-04 113 views
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"); 

} 

这里是我的头文件的一部分:无法将参数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但也没有工作。

+0

您正在使用[保留标识符](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

+0

您的编译器是否为该错误输出了一些行号?如果没有,你是否逐行删除,直到你确定了错误的行? – harper 2012-08-04 04:26:43

回答

2

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

+0

谢谢,我很欣赏反馈 – tensuka 2012-08-04 16:31:33

1

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

+0

谢谢,我很欣赏反馈 – tensuka 2012-08-04 16:31:06

相关问题