Apr 3, 2013 at 12:30pm UTC
You do not initialize *order before calling readOrder, you do that directly afterwards.
Also *& syntax is weird (reference to a pointer?) and unnecessary, just use * as function argument.
Apr 3, 2013 at 1:03pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
void readOrder( OrderList *&order , int &orderIndex ){
ifstream inFile;
string name = "" ;
string item = "" ;
string status = "" ;
string model = "" ;
int quan = 0;
double price = 0.00;
inFile.open("order.txt" );
if ( inFile.fail() )
cout << "Unable to open file " << endl;
inFile >> orderIndex;
order = new OrderList[orderIndex+1];
for ( int i = 0 ; i < orderIndex ; i++){
getline( inFile , name );
order[i].setCompanyName(name);
getline( inFile , item );
order[i].setItemName( item );
getline( inFile , model );
order[i].setModelName( model );
inFile >> price;
order[i].setPrice( price );
inFile >> quan;
order[i].setQuantity( quan );
getline( inFile , status );
order[i].setOrderStatus( status );
}
}
why i read file my file output will be like this
1 2 3 4 5 6 7 8 9 10 11 12 13
2
Kezn
Hitachi
0
0
Jye
LG
LG-ST-244/TV
2
11998
pending
the second correct but why first 1 wrong and run
Last edited on Apr 3, 2013 at 1:16pm UTC
Apr 3, 2013 at 1:18pm UTC
remove the & in OrderList *&order
Apr 3, 2013 at 1:36pm UTC
No, you'll need to dereference order in the readOrder function like so:
(*order)
Then you can (assuming you have overloaded the [] operator) perform:
(*order)[i].setItemName(...);
Another way is to accept the parameter as OrderList &order
and to pass it whilst dereferencing:
readOrder( *order ,inFile , orderIndex );
If you do this then you do not need to change the indexing code in your readOrder function.
Apr 3, 2013 at 1:58pm UTC
solved it.
and
@bour
thanks for your teaching but you are wrong.
i can use *& as my deferencing pointer as well in my function .
i now able to do it. without doing the overload operator..