473,395 Members | 1,653 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,395 software developers and data experts.

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>::isEmpty() 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>::isFull() const
{
return (top >= (size - 1));
}

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

//---------------------------------------main.cpp------------------------------------------------------
#include "stdafx.h"
#include <iostream>#include "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 2936
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
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...
1
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,...
3
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...
2
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...
0
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...
4
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 :...
0
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...
1
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...

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.