Private Node Ctor in LL Trouble

The following is a linked list header file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// list.h
class list
{
public:
	list(void);				// constructor
	virtual ~list(void);	// destructor
	void displayByName(ostream& out) const;
	void displayByRating(ostream& out) const;
	void insert(const winery& winery);
	winery * const find(const char * const name) const;
	bool remove(const char * const name);

private:
	struct node
	{
		node(const winery& winery);		// constructor
		winery item;
		node * nextByName;
		node * nextByRating;
	};

	node * headByName;
	node * headByRating;
};


the winery ctor has 4 param's as follows:
1
2
3
4
// code in main.cpp
// this statement is very important
// I am trying to add the info to the list as a reference to the node ctor
wineries->insert(winery("Lopez Island Vinyard", "San Juan Islands", 7, 95));


I execute the code so far.
I debug and it takes me to the ctor. I use the ctor init list to initialize
the private member varaibles.

1
2
3
4
5
6
7
//winery.cpp
winery::winery(const char * const name, const char * const location, const int acres, const int rating)
  : name( new char[strlen(name)+1] ), location( new char[strlen(location)+1] ), acres( 0 ), rating( 0 )
{	
	// arcres, name, location, rating, are all private members of the winery class
	
}



then we go to the linkedlist:
1
2
3
4
5
6
7
8
//list.cpp
void list::insert(const winery& winery)
{	
	list *ListPtr = new list();
// here im trying to add all the info to the list:
	node *NodePtr = new node( winery );
		
}


I get a linker error: LNK2019: unresolved external symbol "public: __thiscall list::node::node(class winery const &)" (??0node@list@@QAE@ABVwinery@@@Z) referenced in function "public: void __thiscall list::insert(class winery const &)" (?insert@list@@QAEXABVwinery@@@Z)

because the node ctor is a a structure that is private to the linked list? list.cpp?
Actually that error isn't about the fact that node is a private member of list, it is saying that the actual body of the node::node constructor is missing.

In other words have you written the node::node(const winery& winery)
function???
Intellsense does not come up when attempting to write node::node(const winery& winery)

I can keep trying with
1
2
3
list::node(const winery& winery)
{
}
but it does not fix the issue.

Im just trying to deal with the insert member function of the list(). It seems Like I should start there given, the code snipped from main.cpp:

wineries->insert(winery("Lopez Island Vinyard", "San Juan Islands", 7, 95))'
it should be

list::node::node( const winery& w ) { }

Given that code, I would need to add a default ctor to the winery header..

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
#ifndef _WINERY_
#define _WINERY_

#include <ostream>

class winery
{
public:
	winery(const char * const name, const char * const location, const int acres, const int rating);
	winery(); // Newly added **Default Ctor**
	virtual ~winery(void);
	const char * const getName() const;
	const char * const getLocation() const;
	const int getAcres() const;
	const int getRating() const;

	// display headings for lists of wineries
	static void displayHeadings(std::ostream& out);

	friend std::ostream& operator<<(std::ostream& out, winery *w);

private:
	char	*name;
	char	*location;
	int		acres;
	int		rating;
};

#endif // _WINERY_ 


Is there a way to make it work without adding a default ctor?

Topic archived. No new replies allowed.