What I am trying to do is overloading the >> operator of my Book class to take an unknown number of integers from the user in one line. After that, I need to create an array of them.
I tried this:
istream& operator>>( istream& in, Book& b )
{
int x;
delete[] b.editionYears;
b.editionNo = 0;
b.editionYears = new int[0];
cin>>x;
b.addEdition(x);
return in;
}
And I call this with
cout << A << endl;
in the test class where A is a Book object.
I tried this but in here, when the user enters something like "1 2 3 4", it only deletes the array and adds 1 to it, in the second call it deletes 1 again and adds 2.
What I expect is, if the user enters "1 2 3 4", it should delete editionYears array, create again and add 1,2,3,4 to it.
So how can I do this? Thanks for any help.