473,780 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error LNK2020: unresolved token

I wrote a simple stack program using class template on VC++ 2003 but am
unable to resolve the following link errors:

LINK : error LNK2020: unresolved token (0A000046) Stack.__dtor
LINK : error LNK2020: unresolved token (0A000048) Stack.__dtor
LINK : fatal error LNK1120: 2 unresolved externals

The following are my source codes:

//-----------------------stack.h----------------------------------------------------
template <class T>

class Stack
{
public:
Stack(int = 10);
~Stack();
bool push(const T&);
bool pop(T&);
bool isEmpty() const;
bool isFull() const;
private:
int size; // Number of elements on stack
int top; // Element at top of stack
T* stackPtr;
};

//------------------------stack.cpp---------------------------------------------------------

#include "stdafx.h"
#using <mscorlib.dll >
using namespace System;
#include "Stack.h"

// ----------------stack-----------------------------
// Constructor with default size 10
// Pre initialize stack with size s or default size 10
// Post nothing
//-------------------------------------------------------
template <class T>
Stack<T>::Stack (int s)
{
size = (s > 0 && s < 1000 ? s : 10);
top = -1;
stackPtr = new T[size];
}

// --------------------push-----------------------------
// Push a new element onto the stack
// Pre check whether stack is full
// Post return true if item pushed into stack,
// false otherwise.
//-------------------------------------------------------
template <class T>
bool Stack<T>::push( const T& pushItem)
{
if (!isFull())
{
stackPtr[++top] = pushItem;
return true;
}
else
return false;
}

// --------------------pop---------------------------------
// Pop an element from the stack
// Pre check whether stack is empty
// Post return true if item popped from stack,
// false otherwise.
//---------------------------------------------------------
template <class T>
bool Stack<T>::pop(T & popItem)
{
if (!isEmpty())
{
popItem = stackPtr[top--];
return true;
}
else
return false;
}

// --------------------isEmpty-----------------------------
// Check whether stack is empty
// Pre nothing
// Post return true if stack is empty,
// false otherwise.
//---------------------------------------------------------
template <class T>
bool Stack<T>::isEmp ty() const
{
return (top <= -1);
}

// --------------------isFull-----------------------------
// Check whether stack is full
// Pre nothing
// Post return true if stack is full,
// false otherwise.
//---------------------------------------------------------
template <class T>
bool Stack<T>::isFul l() const
{
return (top >= (size - 1));
}

// --------------------~Stack------------------------------
// Destroys the stack by deleting its array pointer
// Pre nothing
// Post nothing
//---------------------------------------------------------
template <class T>
Stack<T>::~Stac k()
{
delete[] stackPtr;
}

//---------------------------------------main.cpp------------------------------------------------------
#include "stdafx.h"
#include <iostream>#incl ude "stack.h"
#using <mscorlib.dll >
using namespace System;
using namespace std;

void main()
{
typedef Stack<double> doubleStack;
doubleStack fs(5);
double f = 1.2;
cout << "Pushing elements onto fs:" << endl;
while (fs.push(f))
{
cout << f << ' ';
f += 1.1;
}
cout << endl << "Stack full." << endl<< endl;

cout << "Popping elements from fs:" << endl;
while (fs.pop(f))
{
cout << f << ' ';
}
cout << endl << "Stack empty." << endl<< endl;
}
//--------------------------------end----------------------------------------------------------------------------

Apr 5 '06 #1
2 2971
On 4 Apr 2006 19:28:50 -0700, tl***@bloomberg .net wrote:
I wrote a simple stack program using class template on VC++ 2003 but am
unable to resolve the following link errors:

LINK : error LNK2020: unresolved token (0A000046) Stack.__dtor
LINK : error LNK2020: unresolved token (0A000048) Stack.__dtor
LINK : fatal error LNK1120: 2 unresolved externals

The following are my source codes:


<snip>

Your template implementation code needs to go into the header with the
class template; it has to be available wherever the compiler needs to
instantiate the template.
--
Doug Harrison
Visual C++ MVP
Apr 5 '06 #2
Thanks, you're a gem!

Apr 10 '06 #3

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

Similar topics

1
4334
by: mccoyn | last post by:
I'm porting an old project to use .NET. When I try to link in a static library (.lib) that has a single managed class in it. I get the following errors: LINK : error LNK2020: unresolved token (0600000E) PatInfo::.ctor LINK : error LNK2020: unresolved token (0600000F) PatInfo::Finalize LINK : fatal error LNK1120: 2 unresolved externals I've striped everything out of this library except for the single class which has an empty constructor...
1
9113
by: Tony Baker | last post by:
Hi, If I 1) create a brand new Visual C++ Project -> Class Library (.Net) 2) in the stdafx.h file add #include <atlbase.h> I get the following errors: ------ Build started: Project: testATL, Configuration: Debug Win32 ------ Compiling... Stdafx.cpp
3
2916
by: Simon Jefferies | last post by:
Hello, I am trying to use a Managed C++ .NET (DLL) Class library within my Managed C++ .NET forms application. I have both projects in the same solution and have the class library under my references branch in the forms application. When I build i get the following linker error:-
2
1705
by: Vickie | last post by:
I have a very simple program with some computations. After using NODEFAULTLIB to get rid of LNK2005 errors such as: LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCR71D.dll) Now I have two new LNK2020 errors: LINK : error LNK2020: unresolved token (0A000021) std._Lockit.__dtor LINK : error LNK2020: unresolved token (0A000022) _DebugHeapTag LINK : fatal error LNK1120: 2 unresolved externals
0
1130
by: Stefan | last post by:
Hi, Could anyone share some light on this and how I can work around it. If I have 2 managed c++ dlls (A and B) and B tries to use a native class in A this fails to link. It is easily reproducable by taking the example from: 'http://msdn2.microsoft.com/library/c3d162w5.aspx' And then move the definition(?) of N::N to the cpp file. It will then look like this: // mcppv2_ref_class3.cpp
4
6107
by: Jun | last post by:
anyone know how this error shows? how can i solve this? LINK : error LNK2020: unresolved token (0A0000EA) _AtlBaseModule LINK : error LNK2020: unresolved token (0A0000EC) atlTraceGeneral LINK : error LNK2020: unresolved token (0A0000ED) ?s_trace@CTrace@ATL@@2V12@A LINK : fatal error LNK1120: 3 unresolved externals thanks in advance.
0
2950
by: Roland | last post by:
Hi, ultimately I want to call some unmanaged C++ class that contains some DirectShow code of mine from my C# classes, but for the time being I'd be happy if I could get this to build! I have read the other topics on the same problem here on the groups but haven't found the solution to my problem yet. I have written a managed C++ wrapper class called MDirectShowHandler. This currently wraps only the constructor and destructor calls (see
1
2442
by: Adamirand | last post by:
Dear friends Happy 2006 for all of you. Well, I'm experiencing a little (big) problem with the Linking process of my VC++.NET project, perhaps it's quite easy to overcome it but for me it's not that clear. Going directly to the point it is as follows: *LINK : error LNK2020: unresolved token (0A00003D) linhas2.__dtor LINK : fatal error LNK1120: 1 unresolved externals*
0
1382
by: devmentee | last post by:
Hi All, I am compiling a VS2003 mixed mode C++ DLL under VS2005 and I get the following linker error. I am using STL map inside a C++ class which is compiled as a mixed mode DLL. I have removed /NOENTRY and /Zl switches and tried compiling with msvcrt.lib, however I still get the error below. Any help will be much much appreciated...Many Thanks
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.