473,587 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linker Errors

I have a class:

template <class T>
class linkedlist
{
protected:
class node
{
public:
T data;
node* next;
node* prev;
node() {next = NULL; prev = NULL;};
~node();
} *first;
public:
~linkedlist() { if (first!=NULL) delete first;};
void AddElement(cons t T &data);
T AddElement(istr eam &input);
void Append(const linkedlist* const data);
linkedlist() {first = NULL;};
};

template <class T>
linkedlist<T>:: node::~node()
{
if (next!=NULL)
delete next;

if (prev!=NULL)
prev->next = NULL;
}
That code is in linkedlist.h (some code was taken out). Please note that I
have defined NULL (if undefined) to be 0.

In main.cpp:

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

using namespace std;
int main(int argc, char* argv[])
{
...some code...

linkedlist<int> intlist;

.... some more code...

return 0;
}
When I compile this code, I get a linker error:

Linking...
main.obj : error LNK2001: unresolved external symbol "public: __thiscall
linkedlist<int> ::node::~node(v oid)" (??1node@?$link edlist@H@@QAE@X Z)
Debug/main.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Of course, I know what this means. It's saying that I never defined the
destructor to node. I thought I did. What am I doing wrong?

--
MiniDisc_2k2
To reply, replace nospam.com with cox dot net.

Jul 19 '05 #1
2 3142

"MiniDisc_2 k2" <Ma******@nospa m.com> wrote in message
news:h6******** ********@news2. east.cox.net...
I have a class:

template <class T>
class linkedlist
{
protected:
class node
{
public:
T data;
node* next;
node* prev;
node() {next = NULL; prev = NULL;};
~node();
} *first;
public:
~linkedlist() { if (first!=NULL) delete first;};
void AddElement(cons t T &data);
T AddElement(istr eam &input);
void Append(const linkedlist* const data);
linkedlist() {first = NULL;};
};

template <class T>
linkedlist<T>:: node::~node()
{
if (next!=NULL)
delete next;

if (prev!=NULL)
prev->next = NULL;
}
That code is in linkedlist.h (some code was taken out). Please note that I
have defined NULL (if undefined) to be 0.

In main.cpp:

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

using namespace std;
int main(int argc, char* argv[])
{
...some code...

linkedlist<int> intlist;

... some more code...

return 0;
}
When I compile this code, I get a linker error:

Linking...
main.obj : error LNK2001: unresolved external symbol "public: __thiscall
linkedlist<int> ::node::~node(v oid)" (??1node@?$link edlist@H@@QAE@X Z)
Debug/main.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Of course, I know what this means. It's saying that I never defined the
destructor to node. I thought I did. What am I doing wrong?


VC++ .NET gives

'member functions of nested classes of a template class cannot be defined
outside the class'

which I think is good advice although not standard C++.

g++ 3.2 compiles it fine.

I'd move the definition back inside the class.

john
Jul 19 '05 #2
> VC++ .NET gives

'member functions of nested classes of a template class cannot be defined
outside the class'

which I think is good advice although not standard C++.

g++ 3.2 compiles it fine.

I'd move the definition back inside the class.

john


thanks, yeah that fixed it. Shouldn't have though....
Jul 19 '05 #3

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

Similar topics

0
1787
by: TGF | last post by:
Hello, I am creating a console app. I try to link a static library by including it in the Linker-Input-Additional Dependencies field under the Project properties. Then I specify the path to the library in Linker-General-Addition Library Directories field under the Project options. The first question I have is....is this the correct way to include a static library. If not, then what is the correct way to do it (I need to make .NET...
0
1620
by: TGF | last post by:
Hello, I am creating a console app. I try to link a static library by including it in the Linker-Input-Additional Dependencies field under the Project properties. Then I specify the path to the library in Linker-General-Addition Library Directories field under the Project options. The first question I have is....is this the correct way to include a static library. If not, then what is the correct way to do it (I need to make .NET...
0
2219
by: Tom McDermott | last post by:
I am having linker errors : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types This code linked sucessfully in C++.NET 2002, but does not link (causes several of these metadata errors) in C++.NET 2003.
4
11320
by: Saran | last post by:
Hi All, I'm getting the following linker error when I try to build a library. nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc nafxcw.lib(apphelp.obj) : error LNK2001: unresolved external symbol __mbctype nafxcw.lib(filelist.obj) : error LNK2019: unresolved external symbol __mbctype referenced in function "void __stdcall...
3
3281
by: ralphsieminsky | last post by:
A project compiles fine under VS 2005 RC without the /clr option. However, when /clr is turned on several errors appear: - A symbol exported from a DLL is not found by another DLL referencing it. The name of the symbol present in the DLL, as shown by depends.exe is ?Apply@ScreenContext@@SGPAV1@PAUHWND__@@@Z But the name of the symbol the linker looks for when
0
1747
by: VivekR | last post by:
I have a MFC application developed using VC++ 5. Recently I ported that to VC++ 7.1 and now I am trying to compile the MFC application with /CLR under VC++ 7.1. And I get linker errors referring to one of the libraries that the project uses. Without the /CLR, the project compiles and runs well. There is some library by name task.lib and the code refers to that lib, in the linker step i get the following linker errors:- Task.lib :...
1
2260
by: Felix | last post by:
After porting a project from VC6 to VC.NET 2003 I have a very strange problem generating link error 1104 for import libraries. I just ported the project and made some small adaptions so it fits the new IDE. The project itself links against some import libraries belonging to dll's I wrote (these dll's have been ported too, of course). To keep things simple I only use one import library here. To tell the linker it should link against
1
3283
by: developer | last post by:
Hi All I have made a .NET project. the files included are borland c++ files that i am migrate to VC++ .NET I am using Microsoft Visual C++ .NET 2003. the compilation goes through properly, but throws a load of linker errors
2
2774
by: Oneironaut | last post by:
Hello friends, I have an issue with a linker warning. It is the warning LNK4089. I am working in MSVC6.0 I investigated and this warning tells that the import of the library to which it makes reference is redundant, thus the linker ignores that library in order to make the code smaller. As it is expected, it only appears for release versions.
2
2415
by: Markus Dehmann | last post by:
What to do if an external library is header-files-only (but you have to use it), and you get lots of linker errors? You will necessarily get linker errors "multiple definition of ..." if you try to separate interface from implementation in your own code. The external-library symbols will first be defined in one .o file and then again in the next one that includes the same implementation-heavy header. Is there any way to avoid the...
0
7924
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
6629
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
5722
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
5395
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();...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.