Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

Vote on your favorite hash algorithm here!

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-12-2008, 06:51 PM
nolsen01 nolsen01 is offline
Newbie
 
Join Date: Jan 2008
Posts: 5
Credits: 0
Rep Power: 0
nolsen01 is on a distinguished road
Angry DoublyLinkedList from hell

I don't want to post to much of my code up, because there is a lot, but I'm not sure where to start.

My project is simply to make a Doubly Linked list in C++. I've been working on the same project for weeks because of this one error. Its quite frustrating:

Code:
1>main.obj : error LNK2019: unresolved external symbol "public: class DLNode<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > * __thiscall DLNode<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::getPredecessor(void)" (?getPredecessor@?$DLNode@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEPAV1@XZ) referenced in function "public: void __thiscall DoublyLinkedList<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::addAtTail(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?addAtTail@?$DoublyLinkedList@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>C:\Users\Nick\Documents\Visual Studio 2008\Projects\NewDoublyLinkedList\Debug\NewDoublyLinkedList.exe : fatal error LNK1120: 1 unresolved externals
the basic layout of the program is:

first header file contains a class (and its methods) called SLNode (stands for Singly Linked Node). It has contains a pointer to an SLNode called successor and also a reference to whatever element is being stored. (using generics)

second header file conatains a DLNode class. it contains to pointer to a DLNode called predecessor. DLNode inherits SLNode.

third header file contains a class DoublyLinkedList. It contains (among other things) a method called addAtTail, which is where this error seems to come from.


DLNode has a getPredecessor and setPredecessor method aswell as getSuccessor and setSuccessor method via inheritance through the SLNode class.

Here is some code of possible value, if you need more, let me know:

Code:
template <class E>
void DoublyLinkedList<E>::addAtTail(E theElement)
{
	DLNode<E> newNode(theElement);
	DLNode<E> *previousNode = tail.getPredecessor(); //returns a pointer

	newNode.setSuccessor(&tail);
	newNode.setPredecessor(previousNode);
	previousNode->setSuccessor(&newNode);
	tail.setPredecessor(&newNode);
}
Code:
template <class E>
DLNode<E> DLNode<E>::*getPredecessor()
{
	return this->predecessor;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 05-13-2008, 02:24 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,535
Last Blog:
wxWidgets is NOT code ...
Credits: 919
Rep Power: 28
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: DoublyLinkedList from hell

Is the definition for DLNode included into this file?
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-13-2008, 02:55 PM
nolsen01 nolsen01 is offline
Newbie
 
Join Date: Jan 2008
Posts: 5
Credits: 0
Rep Power: 0
nolsen01 is on a distinguished road
Default Re: DoublyLinkedList from hell

Here is my code:

DoublyLinkedList.h
Code:
#ifndef DOUBLYLINKEDLIST_H
#define DOUBLYLINKEDLIST_H

#include "DLNode.h"

template <class E>
class DoublyLinkedList
{
private:
	DLNode<E> *head;
	DLNode<E> *tail;
	int length;
public:
	DoublyLinkedList();
	E getElementAt(int pos);
	DLNode<E> find(int pos);
	void addAtHead(E theElement);
//	void addAtTail(E theElement);
	void add(E theElement, int p);
	E remove(int p);
};

template <class E>
DoublyLinkedList<E>::DoublyLinkedList()
{

	DLNode<E> newTailNode;
	DLNode<E> newHeadNode;
	this->tail = &newTailNode;
	this->head = &newHeadNode;
	newTailNode.setSuccessor(*tail);
	newTailNode.setPredecessor(NULL);
	newHeadNode.setPredecessor(*head);
	newHeadNode.setSuccessor(NULL);

	this->length = 0;
}

template <class E>
E DoublyLinkedList<E>::getElementAt(int pos)
{
	if (pos > this->length)
		return NULL;
	else if(pos < 0)
		return NULL;
	else if(pos == 0)
		return NULL;

	return find(pos).getElement();
}

template <class E>
DLNode<E> DoublyLinkedList<E>::find(int pos)
{
	DLNode<E> cursor = head.returnSuccessor();

	int i = 0;
	while(i != pos)
	{
		cursor = cursor.getSuccessor();
		i++;
	}

	return cursor;
}

template <class E>
void DoublyLinkedList<E>::addAtHead(E theElement)
{
	DLNode<E> newNode(theElement, (DLNode<E> *)head->getSuccessor(), head);
	DLNode<E> *node2 = (DLNode<E> *)head->getSuccessor();
	node2->setPredecessor(newNode);
	head->setSuccessor(newNode);
}

/*
template <class E>
void DoublyLinkedList<E>::addAtTail(E theElement)
{
	DLNode<E> newNode(theElement);
	//DLNode<E> previousNode; 
	//previousNode.setEqualTo(tail.getPredecessor());

	newNode.setSuccessor(this->tail);
	newNode.setPredecessor(this->tail->getPredecessor());
	tail->getPredecessor()->setSuccessor(&newNode);
	tail->setPredecessor(&newNode);
}
*/


#endif
SLNode.h
Code:
#ifndef _SLNODE_H
#define _SLNODE_H

template <class E>
class SLNode
{
private:
	E element;
	SLNode<E> *successor;
public:
	SLNode();
	SLNode(E theElement);
	SLNode(E theElement, SLNode<E> theSuccessor);
	E getElement();
	void setElement(E newElement);
	SLNode<E> *getSuccessor();
	void setSuccessor(SLNode<E> newSuccessor);
	//SLNode<E> &operator = (SLNode<E> node);
};

template <class E>
SLNode<E>::SLNode()
{
	this->successor = NULL;
	this->element = NULL;
}

template <class E>
SLNode<E>::SLNode(E theElement)
{
	this->successor = NULL;
	this->element = theElement;
}


template <class E>
SLNode<E>::SLNode(E theElement, SLNode<E> theSuccessor)
{
	this->element = theElement;
	this->successor = &theSuccessor;
}

template <class E>
E SLNode<E>::getElement()
{
	return this->element;
}

template <class E>
void SLNode<E>::setElement(E newElement)
{
	this->element = newElement;
}

template <class E>
SLNode<E> *SLNode<E>::getSuccessor()
{
	return this->successor;
}

template <class E>
void SLNode<E>::setSuccessor(SLNode<E> newSuccessor)
{
		this->successor = &newSuccessor;
}


#endif

DLNode.h:
Code:
#ifndef _DLNODE_H
#define _DLNODE_H
#include "SLNode.h"

template <class E>

class DLNode : public SLNode<E>
{
private:
	DLNode<E> *predecessor;
public:
	DLNode();
	DLNode(E &theElement);
	DLNode(E theElement, DLNode<E>	*theSuccessor, DLNode<E> *thePredecessor);
	DLNode<E> *getPredecessor();
	void setPredecessor(DLNode<E> newSuccessor);
	//void setEqualTo(DLNode<E> *newNode);
};

template <class E>
DLNode<E>::DLNode():SLNode()
{
	this->setPredecessor(NULL);
}

template <class E>
DLNode<E>::DLNode(E &theElement):SLNode(theElement)
{
	this->setPredecessor(NULL);
}

template <class E>
DLNode<E>::DLNode(E theElement, DLNode<E> *theSuccessor, DLNode<E> *thePredecessor)
{
	this->setSuccessor(*theSuccessor);
	this->setElement(theElement);
	this->setPredecessor(*thePredecessor);
	
}

template <class E>
DLNode<E> *DLNode<E>::getPredecessor()
{
	return this->predecessor;
}

template <class E>
void DLNode<E>::setPredecessor(DLNode<E> newPredecessor)
{
	this->predecessor = &newPredecessor;
}

#endif

I've changed quite a bit since I've posted the original problem. Originally, I was going to create an addAtTail() method but even my professor can't seem to figure this one out so I tried instead to just write an addAtHead() method and worry about it later. I'm still running into problems.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Post your funny jokes/brain teasers here littlefranciscan The Lounge 181 02-02-2008 01:06 AM


All times are GMT -5. The time now is 08:48 PM.

Contest Stats

Xav ........ 1357.94
MeTh0Dz|Reb0rn ........ 1075.89
WingedPanther ........ 919.18
marwex89 ........ 906.86
morefood2001 ........ 900.18
John ........ 890.77
Brandon W ........ 770.65
chili5 ........ 312.39
Steve.L ........ 264.99
dcs ........ 232.34

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 83%

Ads