I’m not sure why my display function isn’t working. My cout statement is stating something like
no match for operator << in std :: cout<<n->movieinventory::movienode::m
Any ideas?
class MovieInventory
{
private:
struct MovieNode // the Nodes of the linked list
{
Movie m; // data is a movie
MovieNode *next; // points to next node in list
};
MovieNode *movieList; // the head pointer
bool removeOne(Movie); // local func, used by sort and removeMovie
public:
MovieInventory();
bool addMovie(Movie);
int removeMovie(Movie);
void showInventory();
Movie findMinimum(); // should be private, but public for testing
void sortInventory();
int getTotalQuantity();
float getTotalPrice();
};
Display code:
void MovieInventory::showInventory()
{
MovieNode *n;
for (n = movieList; n != NULL; n = n->next)
cout << n->m;
}
The data member
mbelongs to theMovieclass. Thecoutwith<<operator is overloaded only for the built in data types as int, char, float, etc. So it would not output the object of your user defined data type. You have to overload the<<operator for your own class for that.If you do not want to overload the opeator <<, you have to output the data members of the Movie class one by one this way, provided they are publicy declared.
If data members of the Movie class are private, you would have to make getter functions for that.