Sunday, April 22, 2018

c++ - Private Node Ctor in LL trouble

The following is a linked list header file:



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



// 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.



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



//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?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...