2012-08-04 44 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

相關問題