accessing structure issues
Can anyone please show me whats going wrong here.
I'm trying to access a structure from within another structure but am recieving errors.
Structures are global and are as follows:
Code:
struct StockItem
{
int code;
char desc[20];
float price;
}stock[NUM_OF_ITEMS];
struct BillLine
{
StockItem stock;
float weight;
float cost;
}bill_line[50];
The 'stock' array is already populated.
My code is as follows:
Code:
BillLine bill_item(void)
{
BillLine bill;
int item;
cls();
cout << "Enter item number purchased: ";
cin >> item;
item -= 1;
/*line 213*/ bill.stock = stock[item];
cout << "Weight: ";
cin >> bill.weight;
bill.cost = stock[item].price * bill.weight;
return (bill);
}
void print_bill ( BillLine bill_line[50], int num_bill_items )
{
for (int i=0; i<num_bill_items; ++i)
{
/*line 240*/ cout << "Name = " << bill_line[i].stock.desc << endl;
cout << "Weight = " << bill_line[i].weight << endl;
cout << "Cost = " << bill_line[i].cost << endl;
}
}
MY compile log is as follows:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Ged\code\assignment\best.cpp" -o "C:\Ged\code\assignment\best.exe" -g3 -O0 -g3 -I"C:\Ged\Dev-Cpp\include\c++" -I"C:\Ged\Dev-Cpp\include\c++\mingw32" -I"C:\Ged\Dev-Cpp\include\c++\backward" -I"C:\Ged\Dev-Cpp\include" -L"C:\Ged\Dev-Cpp\lib"
C:/Ged/code/assignment/best.cpp: In function `BillLine bill_item()':
C:/Ged/code/assignment/best.cpp:213: incompatible types in assignment of `
StockItem' to `StockItem[125]'
C:/Ged/code/assignment/best.cpp: In function `void print_bill(BillLine*, int)':
C:/Ged/code/assignment/best.cpp:240: request for member `desc' in `(bill_line +
(+(i * 3508)))->BillLine::stock', which is of non-aggregate type `
StockItem[125]'
Execution terminated