I'm writing a program that creates a lists of bikes from a file. Currently, I think I have everything correct up to the sell one bike function. I'm getting some errors and I'm not sure what's going on..
prog3.cpp: In function 'void SellOneBike(Motorcycles*&)':
prog3.cpp:110: error: 'tStockNum' was not declared in this scope
prog3.cpp:111: error: expected primary-expression before '->' token
prog3.cpp:113: error: expected primary-expression before '->' token
prog3.cpp:114: error: expected primary-expression before ';' token
prog3.cpp:115: error: 'Motorcycle' was not declared in this scope
~/cs2020c$
Since I'm new to linked lists, I don't know what these mean. Could someone please help me out here? Here's my program: See revised program below.
struct Motorcycle{
//...
Motorcycle *next; //this is a bad idea
};
The object should not know that is inside a container. Separate the logic.
1 2 3 4 5 6 7 8 9 10 11 12
void SellOneBike(Motorcycles *&firstMotorcycle)
{
indata >> tStockNum; //what is tStockNum? it was never declared
if (Motorcycles->StockNum == indata >> tStockNum) //Motorcycles is a class, not an object
{
firstMotorcycle = Motorcycles->next;
delete Motorcycles;
Motorcycles = firstMotorcycle;
cout << "Bike number " << tStockNum << " has been sold." << endl;
}
}
if (Motorcycles->StockNum == indata >> tStockNum) The insertion operator returns an istream. However, why do you read again?
1 2 3 4 5 6
//typedef node_motorcycle* iterator;
iterator list_motorcycle::find( const Motorcycle & ) const;
list_motorcycle::erase( iterator );
//then you do
m.erase( m.find( Motorcycle(tStockNum) )
Thanks for the info ne555. I've made some changes to my program but I'd like to focus on my SellOneBike function because that's where my errors are coming from.
To be celar, my struct is just supposed to be a struct, not a class. We're just now learning classes.