GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Feb-2009, 10:02
smack1878 smack1878 is offline
New Member
 
Join Date: Feb 2009
Posts: 2
smack1878 is on a distinguished road

Error LNK2019: unresolved external symbol...


Hi, I´m new to c++ and inheritance therefore I have a problem with this code. Please help

I want to create two classes ("leaf" and "internal") that inherit from "node". I removed everything from the code to reproduced the error.
When I call a function that uses "node" in "leaf.cpp" a link error occurs :S

The error is:
Linking...
leaf.obj : error LNK2019: unresolved external symbol "public: void __thiscall node::test(class node *)" (?test@node@@QAEXPAV1@@Z) referenced in function "public: void __thiscall leaf::test(class node *)" (?test@leaf@@QAEXPAVnode@@@Z)
C:\Documents and Settings\MiguelDeVezEmQuando\My Documents\Visual Studio 2005\Projects\tree\Debug\tree.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\MiguelDeVezEmQuando\My Documents\Visual Studio 2005\Projects\tree\tree\Debug\BuildLog.htm"
tree - 2 error(s), 0 warning(s)


I got three ".h"s
Node.h
CPP / C++ / C Code:
 
#ifndef nodeH
#define nodeH

class node {
	public:
	node* k;
	void test(node* in);
};

#endif


Leaf.h
CPP / C++ / C Code:
 
#include "node.h"

#ifndef leafH
#define leafH

class leaf : public node {
public:
void test(node* in);
};

#endif



Internal.h
CPP / C++ / C Code:
 
#include "node.h"

#ifndef internalH
#define internalH

class internal : public node{
	public:
	node* j;
	void test(node* in);
};

#endif



And one CPP
Leaf.cpp
CPP / C++ / C Code:
 
#include "leaf.h"

#ifndef leafCPP
#define leafCPP


void leaf::test(node* in)
{
	in->test(in);
}

int main()
{
	return 0;
}

#endif
  #2  
Old 18-Feb-2009, 11:22
smack1878 smack1878 is offline
New Member
 
Join Date: Feb 2009
Posts: 2
smack1878 is on a distinguished road

Re: inheritance problem, please help :P


The solution for this lnk2019 error is solved (Hurray) with a virtual destructor in class Node (though I dont understand why :S).
  #3  
Old 19-Feb-2009, 06:06
Alexandra Alexandra is offline
New Member
 
Join Date: Jan 2009
Posts: 2
Alexandra is an unknown quantity at this point

Re: Error LNK2019: unresolved external symbol...


For future reference, let's look at the error again. It's very informative, actually.
leaf.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall node::test(class node )"
"unresolved external symbol" basically means the linker could not find a variable or function.
And...
virtual void __thiscall node::test(class node *)
Tells us that the function in question is the member function test inside class node that takes a node as argument.

Possible reasons as to why it cannot find it is that...
1) You have a function which you forgot to implement (ie, you simply forgot or you misspelled the name).
2) Misspelled variable.
3) All source files weren't compiled properly (can sometimes happen; a rebuild will likely solve that in VS
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache Web Server newbie problem niss3 Apache Web Server Forum 1 13-Apr-2009 19:38
Inheritance Suspicious Problem Peter_APIIT C++ Forum 12 15-May-2007 23:01
Class inheritance problem Sita C++ Forum 11 07-Apr-2006 11:20
inheritance problem ap6118 C++ Forum 8 11-Apr-2005 12:24
Inheritance problem CaptnB C++ Forum 2 27-Jan-2005 09:09

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:54.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.