Cannot define the Default Constructor

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):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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(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.
	bool remove(const char * 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.

1
2
3
4
5
6
7
8
9
list::list()
{
//default constructor
}

list::~list()
{
//default destructor
}


Because the class includes a struct, it proves to me difficult. Any ideas on what I should do?
Last edited on
Well... what exactly do you need to do upon initializing the code?

-Albatross
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
1
2
3
	
        list(void);				// constructor
	virtual ~list(void);	// destructor 


change to
1
2
3
	
        list();				// constructor
	virtual ~list();	// destructor 


This is a p problem also:

node(const cafe& cafe);//Error variable name conflicts with the name of the class
Last edited on
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.
Last edited on

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

Yes the problem is there.

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.


Really? I don't think so.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>

std::string* const foo() {
    static std::string s( "Hello World!" );
    return &s;
}

int main() {
    std::string* const ps = foo();
    (*ps)[ 0 ] = 'J';
    std::cout << *ps << std::endl;
}


Outputs


Jello World!

Topic archived. No new replies allowed.