I need help defining the default constructor for this following block of code. It's a list object that contains a linked list of coffeehouses, rated in two categories (name and rating):
class list
{
public:
list(void); // constructor
virtual ~list(void); // destructor
void displayByName(ostream& out) const;
void displayByRating(ostream& out) const;
void insert(const cafe& cafe);
cafe * const find(constchar * const name) const;
// Returns a const pointer to the cafe instance it found in
// the list, or 0 if it didn't find a cafe with that name.
// Because the pointer is declared const, there is no danger
// that find's caller will be able to use the returned pointer
// to change the instance of cafe.
bool remove(constchar * const name);
private:
struct node
{
// constructor
node(const cafe& cafe);
cafe item;
node * nextByName;
node * nextByRating;
};
node * headByName;
node * headByRating;
};
#endif // _LIST_
This is where I should put in the constructor and destructor.
The struct is only a declaration.
I see no objects of struct node declared in the list class.
by the way the Standard library already contains a class called list - maybe you want to change the spelling of your class to List or something like that to prevent any future problems.
It's up to you.
PS - when a c++ function takes no parameters, there is no neeed to put void
Appreciate the code editing, but I do not care for it. And besides the code was not prepared by me, it was prepared by my CS professor. I just want to know how can I create a default constructor for this particular code? I want to do this in order to create a linked list that goes in two forms: nextByName, and nextByRating, and so that I could have a clear idea on what to do next.
If there's any ideas, I will ask elsewhere. Thank you.
by the way the Standard library already contains a class called list - maybe you want to change the spelling of your class to List or something like that to prevent any future problems.
Don't bother on that one because it won't pollute the global namespace.
it's
std::list
not
::list
Note that those above two things are not identical.In other words
1 2 3 4 5 6 7 8 9 10 11 12
class list
{
public:
list()
{
}
void FooBar(void)
{
return;
}
};
is completely a valid code nor it does override the std::list .
This is a p problem also:
node(const cafe& cafe);//Error variable name conflicts with the name of the class
cafe * const find(const char * const name) const;
// Returns a const pointer to the cafe instance it found in
// the list, or 0 if it didn't find a cafe with that name.
// Because the pointer is declared const, there is no danger
// that find's caller will be able to use the returned pointer
// to change the instance of cafe.