![](/img/trans.png)
[英]cannot convert from 'std::vector<_Ty>' to 'std::vector<_Ty> &
[英]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");
}
这是我的头文件的一部分:
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....。我也尝试过* Master._Inv,但是也没有用。
该错误消息非常简单。 addCart
, removeCart
和checkout
都将指向Inventory
的指针作为参数。 但是您的参数&Master._Inv
是指向std::vector<Food>
的指针。 也许您的意思是&Master
?
Customer :: addCart()的第三个参数是指向库存对象的指针。 尝试通过&Master。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.