tags:

views:

61

answers:

3

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?

+2  A: 

where and how did you provide the implementation for the constructor of node? it can't find it

newacct
+1  A: 

You have either forgotten to define (in addition to declaring) the constructor for list::node, or you have forgotten to link the object file produced from .cpp file with the definition of that constructor into your application. This:

node(const winery& winery);

is only a declaration, not a definition (since it lacks the body).

Pavel Minaev
+3  A: 

You're declaring this constructor for node, but no other constructors:

node(const winery& winery)

Then later, you're implementing a constructor for winery, but not for node (that's shown):

winery::winery(const char * const name, const char * const location, const int acres, const int rating)

The files compile due to the declaration, but the linker will fail.

Nowhere are you (in the code you're showing) actually implementing the constructor for node. Somewhere, according to your code, you need to declare and implement a constructor that takes a winery as an argument. The error says that the linker cannot find the appropriate constructor.

Reed Copsey