Click here to Skip to main content
15,916,941 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Edit box and associated CString Pin
RChin15-Sep-04 5:17
RChin15-Sep-04 5:17 
Generalfunction problem Pin
ISUstudent15-Sep-04 4:25
ISUstudent15-Sep-04 4:25 
GeneralRe: function problem Pin
David Crow15-Sep-04 4:49
David Crow15-Sep-04 4:49 
GeneralRe: function problem Pin
ISUstudent15-Sep-04 4:51
ISUstudent15-Sep-04 4:51 
GeneralRe: function problem Pin
David Crow15-Sep-04 5:10
David Crow15-Sep-04 5:10 
GeneralRe: function problem Pin
David Crow24-Sep-04 6:06
David Crow24-Sep-04 6:06 
GeneralRe: function problem Pin
Anonymous24-Sep-04 6:57
Anonymous24-Sep-04 6:57 
GeneralLinkedList Template - LNK2019 Pin
Milby00715-Sep-04 4:06
Milby00715-Sep-04 4:06 
hi!

i've just finished writing a linked list template class, which compiles fine, but when i try to use it in another file (main.cpp) in my console test app' i get LNK2019 errors for every method of the class being used. i've copied the class & output below, so if anyone has any ideas i would REALLY appreciate some help because i'm completely stuck!! thanks!!

#ifndef _LINKEDLIST_H_
#define _LINKEDLIST_H_

#pragma message (" -+- COMPILING " __FILE__)

// declare classes...

template <class type> class ListElement;
template <class type> class LinkedList;

/*
************************
linkedlist class
************************
*/

template <class type> class LinkedList
{
public:

//
// constructor/destructor
//

LinkedList<type>();
~LinkedList<type>();

//
// public methods
//

bool InsertNext(ListElement<type>* pElement, const type* pData);
bool RemoveNext(ListElement<type>* pElement, type** ppData);

ListElement<type>* GetHead();
ListElement<type>* GetTail();

int GetSize();

bool IsHead(const ListElement<type>& element);
bool IsTail(const ListElement<type>& element);
bool IsEmpty();

ListElement<type>* GetElementByIndex(int index);

LinkedList<type>* Clone();
LinkedList<type>* Copy();

void FreeData();

private:

//
// private methods
//

void SetHead(ListElement<type>* pHead);
void SetTail(ListElement<type>* pTail);
void SetSize(int size);

//
// private member data
//

int m_size;
ListElement<type>* m_pHead;
ListElement<type>* m_pTail;

};

/*
*************************
listelement class
*************************
*/

template <class type> class ListElement
{
public:

//
// constructor/destructor
//

ListElement();
~ListElement();

//
// public methods
//

type* GetData();
void SetData(type* pData);

void FreeData();

ListElement<type>* GetNext();
void SetNext(ListElement<type>* pNext);

type* CloneData();

private:

//
// private member data
//

type* m_pData;
ListElement<type>* m_pNext;

};

#endif // _LINKEDLIST_H_


#pragma message (" -+- COMPILING " __FILE__)

#include <stdlib.h>
#include "linkedlist.h"

/*
************************
linkedlist class
************************
*/

template <class type>
LinkedList<type>::LinkedList() : m_size(0), m_pHead(NULL), m_pTail(NULL)
{
// do nothing
}

template <class type>
LinkedList<type>::~LinkedList()
{
if (m_pHead != NULL)
delete m_pHead;
}

template <class type>
bool LinkedList<type>::InsertNext(ListElement<type>* pElement, const type* pData)
{
ListElement<type>* pNewElement = new ListElement<type>;

if (pNewElement == NULL)
return false;

pNewElement->SetData(const_cast<type*> (pData));

if (pElement == NULL) // insertion @ head of list...
{
if (this->GetSize() == 0)
this->SetTail(pNewElement);

pNewElement->SetNext(this->GetHead());
this->SetHead(pNewElement);
}
else // insertion somewhere other than @ the head...
{
if (pElement->GetNext() == NULL)
this->SetTail(pNewElement);

pNewElement->SetNext(pElement->GetNext());
pElement->SetNext(pNewElement);
}

this->SetSize(this->GetSize() + 1);

return true;
}

template <class type>
bool LinkedList<type>::RemoveNext(ListElement<type>* pElement, type** ppData)
{
ListElement<type>* pOldElement;

if (this->GetSize() == 0)
return false;

// if null then handle removal from head of list...
if (pElement == NULL)
{
*ppData = this->GetHead()->GetData();
pOldElement = this->GetHead();
this->SetHead(this->GetHead()->GetNext());

if (this->GetSize() == 1)
{
this->SetTail(NULL);
}
}
else
{
if (pElement->GetNext() == NULL)
return false;

*ppData = pElement->GetNext()->GetData();
pOldElement = pElement->GetNext();
pElement->SetNext(pElement->GetNext()->GetNext());

if (pElement->GetNext() == NULL)
{
this->SetTail(pElement);
}
}

delete pOldElement;

this->SetSize(this->GetSize() - 1);

return true;
}

template <class type>
ListElement<type>* LinkedList<type>::GetHead()
{
return m_pHead;
}

template <class type>
ListElement<type>* LinkedList<type>::GetTail()
{
return m_pTail;
}

template <class type>
int LinkedList<type>::GetSize()
{
return m_size;
}

template <class type>
bool LinkedList<type>::IsHead(const ListElement<type>& element)
{
return this->GetHead() == element ? true : false;
}

template <class type>
bool LinkedList<type>::IsTail(const ListElement<type>& element)
{
return this->GetTail() == element ? true : false;
}

template <class type>
bool LinkedList<type>::IsEmpty()
{
return this->GetSize() == 0 ? true : false;
}

template <class type>
ListElement<type>* LinkedList<type>::GetElementByIndex(int index)
{
int i;
ListElement<type>* pTmp = NULL;

if (this->GetSize() == 0 || index >= this->GetSize())
return pTmp;

pTmp = this->GetHead(); // element zero

for (i = 1; i <= index; i++)
{
pTmp = pTmp->GetNext();
}

return pTmp;
}

template <class type>
LinkedList<type>* LinkedList<type>::Clone()
{
LinkedList<type>* pNewList = NULL;
ListElement<type>* pSrcElement = NULL;

if (this->GetSize() == 0)
return pNewList;

pNewList = new LinkedList<type>;
pSrcElement = this->GetHead();

pNewList->InsertNext(NULL, pSrcElement->CloneData());

while (pSrcElement->GetNext() != NULL)
{
pSrcElement = pSrcElement->GetNext();

pNewList->InsertNext(pNewList->GetTail(), pSrcElement->CloneData());
}

return pNewList;
}

template <class type>
LinkedList<type>* LinkedList<type>::Copy()
{
LinkedList<type>* pNewList = NULL;
ListElement<type>* pSrcElement = NULL;

if (this->GetSize() == 0)
return pNewList;

pNewList = this;
pSrcElement = this->GetHead();

pNewList->InsertNext(NULL, pSrcElement->CloneData());

while (pSrcElement->GetNext() != NULL)
{
pSrcElement = pSrcElement->GetNext();

pNewList->InsertNext(pNewList->GetTail(), pSrcElement->GetData());
}

return pNewList;
}

template <class type>
void LinkedList<type>::FreeData() // only call when data is allocated on the heap
{
ListElement<type>* pElement = NULL;

if (this->GetSize() == 0)
return;

pElement = this->GetHead();
pElement->FreeData();

while (pElement->GetNext() != NULL)
{
pElement = pElement->GetNext();
pElement->FreeData();
}
}

template <class type>
void LinkedList<type>::SetHead(ListElement<type>* pHead)
{
m_pHead = pHead;
}

template <class type>
void LinkedList<type>::SetTail(ListElement<type>* pTail)
{
m_pTail = pTail;
}

template <class type>
void LinkedList<type>::SetSize(int size)
{
m_size = size;
}

/*
*************************
listelement class
*************************
*/

template <class type>
ListElement<type>::ListElement<type>() : m_pData(NULL), m_pNext(NULL)
{
// do nothing
}

template <class type>
ListElement<type>::~ListElement<type>()
{
if (m_pNext != NULL)
delete m_pNext;
}

template <class type>
type* ListElement<type>::GetData()
{
return m_pData;
}

template <class type>
void ListElement<type>::SetData(type* pData)
{
m_pData = pData;
}

template <class type>
void ListElement<type>::FreeData()
{
if (m_pData != NULL)
delete m_pData;
}

template <class type>
ListElement<type>* ListElement<type>::GetNext()
{
return m_pNext;
}

template <class type>
void ListElement<type>::SetNext(ListElement<type>* pNext)
{
m_pNext = pNext;
}

template <class type>
type* ListElement<type>::CloneData()
{
type* pNewData = new type;

*pNewData = *m_pData;

return pNewData;
}

Linking...
main.obj : error LNK2019: unresolved external symbol "public: __thiscall Stack<int,100>::~Stack<int,100>(void)" (??1?$Stack@H$0GE@@@QAE@XZ) referenced in function "void __cdecl stackfunc(void)" (?stackfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: __thiscall Stack<double,30>::~Stack<double,30>(void)" (??1?$Stack@N$0BO@@@QAE@XZ) referenced in function "void __cdecl stackfunc(void)" (?stackfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Stack<int,100>::push(int const &)" (?push@?$Stack@H$0GE@@@QAEXABH@Z) referenced in function "void __cdecl stackfunc(void)" (?stackfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Stack<double,30>::push(double const &)" (?push@?$Stack@N$0BO@@@QAEXABN@Z) referenced in function "void __cdecl stackfunc(void)" (?stackfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: bool __thiscall Stack<int,100>::isEmpty(void)const " (?isEmpty@?$Stack@H$0GE@@@QBE_NXZ) referenced in function "void __cdecl stackfunc(void)" (?stackfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: __thiscall Stack<double,30>::Stack<double,30>(void)" (??0?$Stack@N$0BO@@@QAE@XZ) referenced in function "void __cdecl stackfunc(void)" (?stackfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: __thiscall Stack<int,100>::Stack<int,100>(void)" (??0?$Stack@H$0GE@@@QAE@XZ) referenced in function "void __cdecl stackfunc(void)" (?stackfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: class LinkedList<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > * __thiscall LinkedList<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::Clone(void)" (?Clone@?$LinkedList@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEPAV1@XZ) referenced in function "void __cdecl listfunc(void)" (?listfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: class ListElement<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > * __thiscall LinkedList<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::GetElementByIndex(int)" (?GetElementByIndex@?$LinkedList@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEPAV?$ListElement@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@H@Z) referenced in function "void __cdecl listfunc(void)" (?listfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: class ListElement<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > * __thiscall ListElement<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::GetNext(void)" (?GetNext@?$ListElement@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEPAV1@XZ) referenced in function "void __cdecl listfunc(void)" (?listfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: class ListElement<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > * __thiscall LinkedList<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::GetHead(void)" (?GetHead@?$LinkedList@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEPAV?$ListElement@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@XZ) referenced in function "void __cdecl listfunc(void)" (?listfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: int __thiscall LinkedList<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::GetSize(void)" (?GetSize@?$LinkedList@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEHXZ) referenced in function "void __cdecl listfunc(void)" (?listfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: class ListElement<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > * __thiscall LinkedList<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::GetTail(void)" (?GetTail@?$LinkedList@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEPAV?$ListElement@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@XZ) referenced in function "void __cdecl listfunc(void)" (?listfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: bool __thiscall LinkedList<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::InsertNext(class ListElement<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const *)" (?InsertNext@?$LinkedList@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAE_NPAV?$ListElement@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@PBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "void __cdecl listfunc(void)" (?listfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * __thiscall ListElement<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::GetData(void)" (?GetData@?$ListElement@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEPAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "void __cdecl listfunc(void)" (?listfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: void __thiscall ListElement<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::SetData(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *)" (?SetData@?$ListElement@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEXPAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "void __cdecl listfunc(void)" (?listfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: __thiscall ListElement<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::ListElement<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(void)" (??0?$ListElement@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAE@XZ) referenced in function "void __cdecl listfunc(void)" (?listfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: __thiscall LinkedList<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::LinkedList<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(void)" (??0?$LinkedList@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAE@XZ) referenced in function "void __cdecl listfunc(void)" (?listfunc@@YAXXZ)

main.obj : error LNK2019: unresolved external symbol "public: __thiscall LinkedList<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::~LinkedList<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(void)" (??1?$LinkedList@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAE@XZ) referenced in function "public: void * __thiscall LinkedList<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::`scalar deleting destructor'(unsigned int)" (??_G?$LinkedList@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEPAXI@Z)
Debug/list_test.exe : fatal error LNK1120: 19 unresolved externals

list_test - 20 error(s), 2 warning(s)


---------------------- Done ----------------------

Build: 0 succeeded, 1 failed, 0 skipped


GeneralRe: LinkedList Template - LNK2019 Pin
David Crow15-Sep-04 4:44
David Crow15-Sep-04 4:44 
GeneralRe: LinkedList Template - LNK2019 Pin
Milby00715-Sep-04 5:08
Milby00715-Sep-04 5:08 
GeneralRe: LinkedList Template - LNK2019 Pin
jmkhael15-Sep-04 5:04
jmkhael15-Sep-04 5:04 
GeneralRe: LinkedList Template - LNK2019 Pin
Milby00715-Sep-04 5:20
Milby00715-Sep-04 5:20 
GeneralRe: LinkedList Template - LNK2019 Pin
Bob Stanneveld15-Sep-04 6:31
Bob Stanneveld15-Sep-04 6:31 
QuestionWhat does *.hpp mean? Pin
mcgahanfl15-Sep-04 2:41
mcgahanfl15-Sep-04 2:41 
AnswerRe: What does *.hpp mean? Pin
David Crow15-Sep-04 2:50
David Crow15-Sep-04 2:50 
AnswerRe: What does *.hpp mean? Pin
markkuk15-Sep-04 3:16
markkuk15-Sep-04 3:16 
AnswerRe: What does *.hpp mean? Pin
Henry miller15-Sep-04 3:45
Henry miller15-Sep-04 3:45 
AnswerThank you Dave, Mark and Henry. Pin
mcgahanfl15-Sep-04 4:34
mcgahanfl15-Sep-04 4:34 
GeneralBizarre Close dialog action Pin
brianwelsch15-Sep-04 2:22
brianwelsch15-Sep-04 2:22 
GeneralRe: Bizarre Close dialog action Pin
Cedric Moonen15-Sep-04 2:35
Cedric Moonen15-Sep-04 2:35 
GeneralRe: Bizarre Close dialog action Pin
brianwelsch15-Sep-04 4:18
brianwelsch15-Sep-04 4:18 
GeneralRe: Bizarre Close dialog action Pin
David Crow15-Sep-04 4:58
David Crow15-Sep-04 4:58 
GeneralRe: Bizarre Close dialog action Pin
brianwelsch15-Sep-04 5:42
brianwelsch15-Sep-04 5:42 
GeneralRe: Bizarre Close dialog action Pin
David Crow15-Sep-04 5:48
David Crow15-Sep-04 5:48 
GeneralRe: Bizarre Close dialog action Pin
brianwelsch15-Sep-04 7:33
brianwelsch15-Sep-04 7:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.