Hello daveed,
The short anser is that yo do not call your over loaded "operator <<" or "operator >>" you just use them as in:
1 2 3 4 5 6 7 8 9 10 11
|
int main()
{
ifstream inFile;
// code to open file
Wharhouse warehouse;
infile >> warehouse;
// rest of code
}
|
On line 8 the compiler will pick up on the difference and use your overloaded operator because "warehouse" is a object of the class and not a regular variable.
It would also be helpful if you post the whole code because I see problems in what you have posted. With out the rest of the code it is not easy to tell what is all wrong.
In your first bit of code line 1 includes "Warehouse.h", but how can you include this file before you define the class which comes later.
You include "Book.h", but the contentsare unavailable to see what you did.
Line 8 defines "MAX_BOOKS", but you define it again on line 25. You do not needit twice and it would be better defined in "Book.h" and not "Warehouse.h".
The header files "iostream" and "string" should not be needed in a header file if done correctly.
The line
using namespace std;
should never be in a header file. This is worth reading:
http://www.lonecpluspluscoder.com/2012/09/22/i-dont-want-to-see-another-using-namespace-xxx-in-a-header-file-ever-again/
In the second bit of code "Book.h" tends to work better when it comes after "iostream" and "string".
Since you have forward declared the "<<" and ">>" in "Warehouse.h" you should include this file in the ".cpp" file.
Line 7 was defined in "warehouse.h" and probably in "Book.h" so you do not need it here again. I do not believe the "static" qualifier is needed. I have defined constant variables in header files and have not needed to use "static".
Lines 9 - 17 are global variables and should be avoided. They are better defined inside a function that uses them.
"double" is the preferred floating point type as a "float" is less precise.
I do not know why you have ended your variable names with an underscore, but this form is best left to the include files that come with the compiler. Not to say there is anything wrong with it, but it is not necessary.
This is some of what I see right now compared to what I have done and what I have seen others do.
Hope that helps,
Andy