473,322 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Error LNK2091

Red
I am taking a c++ course. I have a simple program that just wont compile and
I cant seem to figure out why. If I compile the class file without
referencing it in the int main() it will compile but once I try to createon
abject of the class type I get:

Recursive error LNK2019: unresolved external symbol "public: __thiscall
UnsortedList<int>::~UnsortedList<int>(void)" (??1?$UnsortedList@H@@QAE@XZ)
referenced in function _main
Recursive error LNK2019: unresolved external symbol "public: __thiscall
UnsortedList<int>::UnsortedList<int>(void)" (??0?$UnsortedList@H@@QAE@XZ)
referenced in function _main
Recursive is the name of the project.
Please help.
Thanks

Header File
#pragma once

template <class ItemType>

struct NodeType;

template <class ItemType>

class UnsortedList

{

public:

UnsortedList<ItemType>(void);

~UnsortedList<ItemType>(void);

bool IsFull() const;

int LengthIs() ;

void MakeEmpty();

void GetItem(ItemType& item, bool& found);

void InsertItem(ItemType itm);

void DeleteItem(ItemType itm);

void ResetList();

void GetNextItem(ItemType& itm);

private:

NodeType<ItemType>* listData;

int length;

NodeType<ItemType>* currentPos;

};

template <class ItemType>

struct NodeType

{

ItemType info;

NodeType* next;

};

Class Implementation

#include "UnsortedList.h"

template <class ItemType>

UnsortedList<ItemType>::UnsortedList(void)

{

length = 0;

listData = NULL;

}

template <class ItemType>

UnsortedList<ItemType>::~UnsortedList(void)

{

delete currentPos;

delete listData;

}

template <class ItemType>

bool UnsortedList<ItemType>::IsFull() const

{

try

{

location = new NodeType<ItemType>;

delete location;

return false;

}

catch(std::bad_alloc exception)

{

return true;

}

}

template <class ItemType>

int UnsortedList<ItemType>::LengthIs()

{

return length;

}

template <class ItemType>

void UnsortedList<ItemType>::MakeEmpty()

{

NodeType<ItemType>* tempPtr;

while ( listData != NULL )

{

tempPtr = listData;

listData = listData->next;

delete tempPtr;

}

length = 0;

}

template <class ItemType>

void UnsortedList<ItemType>::GetItem(ItemType& itm, bool& found)

{

bool moreToSearch;

NodeType<ItemType>* location;

location = listData;

found = false;

moreToSearch = ( location != NULL );

while ( moreToSearch && !found )

{

if ( itm == location->info )

{

found = true;

itm = location->info;

}

else

{

location = location->next;

moreToSearch = ( location != NULL );

}

}

}

template <class ItemType>

void UnsortedList<ItemType>::InsertItem(ItemType itm)

{

NodeType<ItemType>* location;

location = new NodeType<ItemType>;

location->info = itm;

location->next = listData;

listData = location;

length++;

}

template <class ItemType>

void UnsortedList<ItemType>::DeleteItem(ItemType itm)

{

NodeType<ItemType>* location = listData;

NodeType<ItemType>* tempLocation;

if ( item == listData->info )

{

tempLocation = location;

listData = listData->next;

}

else

{

while ( !(itm == location->next->info ) )

{

location = location->next;

tempLocation = location->next;

location->next = ( location->next)->next;

}

delete tempLocation;

length--;

}

}

template <class ItemType>

void UnsortedList<ItemType>::ResetList()

{

currePos = NULL;

}

template <class ItemType>

void UnsortedList<ItemType>::GetNextItem(ItemType& itm)

{

if ( currentPos == NULL )

{

currentPos = listData;

}

else

{

currentPos = currentPos->next;

}

itm = currentPos->info;

}

Main Driver

#include "UnsortedList.h"

#include <iostream>

using namespace std;

//void PrintList(UnsortedList<int>& list);

int main()

{

UnsortedList<int> list1;

//int itm1;

////fill the first list

//itm1 = 1;

//list1.InsertItem(itm1);

//itm1 = 3;

//list1.InsertItem(itm1);

//itm1 = 5;

//list1.InsertItem(itm1);

//cout << "Printing list 1:" << endl;

//PrintList(list1);

return 0;

}

// void PrintList(UnsortedList<int>& list)

//// Pre: list has been initialized.

//// dataFile is open for writing.

//// Post: Each component in list has been written to dataFile.

//// dataFile is still open.

//{

// int length;

// int item;

// list.ResetList();

// length = list.LengthIs();

// cout << "List Items: " << endl;

// for (int counter = 1; counter <= length; counter++)

// {

// list.GetNextItem(item);

// cout << item << endl;

// }

// cout << endl;

//}
Nov 17 '05 #1
1 2352

--------------------
From: "Red" <wr****@optonline.net>
Subject: Error LNK2091
Date: Wed, 28 Apr 2004 21:55:53 -0400
Lines: 393
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <#d**************@TK2MSFTNGP12.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vc
NNTP-Posting-Host: ool-18ba8c42.dyn.optonline.net 24.186.140.66
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA06.phx.gbl!cpmsftn gxa06.phx.gbl!TK2MSFTNGP08
.phx.gbl!TK2MSFTNGP12.phx.gbl Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.languages.vc:36196
X-Tomcat-NG: microsoft.public.dotnet.languages.vc

I am taking a c++ course. I have a simple program that just wont compile and I cant seem to figure out why. If I compile the class file without
referencing it in the int main() it will compile but once I try to createon abject of the class type I get:

Recursive error LNK2019: unresolved external symbol "public: __thiscall
UnsortedList<int>::~UnsortedList<int>(void)" (??1?$UnsortedList@H@@QAE@XZ)
referenced in function _main
Recursive error LNK2019: unresolved external symbol "public: __thiscall
UnsortedList<int>::UnsortedList<int>(void)" (??0?$UnsortedList@H@@QAE@XZ)
referenced in function _main


No code is generated for templates until they have been instantiated. In
your class implementation, you need to instantiate UnsortedList with int,
in order to produce the function definitions that the main driver requires.
Alternatively, if you don't know the list of types up front (for example,
it's a library with consumers), you could include the class implementation
into the main driver as a header file.

Your example is similar to this:

//test.h
#pragma once
template<class T> class test
{
public:
void func();
};

//test.cpp - implementation
#include "test.h"
template<class T> void test<T>::func()
{
//stuff here
}

//main.cpp - uses test
#include "test.h"
int main()
{
test<int> t;
t.func();
}
And my recommendation to fix it is either:

1) add this line to test.cpp to explicitly instantiate the template for
int: template class test<int>; or,

2) #include "test.cpp" inside main.cpp
--
Arjun Bijanki, Microsoft Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
1
by: Aravind | last post by:
we have two files: 1. rc4.c (defines one function "create_pin()") 2. MyImpl.c(calling the function "create_pin()"),This implements JNI method. 1.When I am trying to create .dll file with one...
1
by: yanwan | last post by:
I met this problem in executing a c++ project in visual studio. Does anyone have suggestions to resolve "error lnk 2001"? --------------------Configuration: reconstruction - Win32...
5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.