Cant create instance of class...

Started by
6 comments, last by rIKmAN 19 years, 5 months ago
Can anyone tell me why the following code won`t compile, when I uncomment the line in main() to create a new instance of the class. It simply gives me:

LinkList.obj : error LNK2001: unresolved external symbol "public: __thiscall LinkList::~LinkList(void)" (??1LinkList@@QAE@XZ)
LinkList.obj : error LNK2001: unresolved external symbol "public: __thiscall LinkList::LinkList(void)" (??0LinkList@@QAE@XZ)
Debug/LinkList.exe : fatal error LNK1120: 2 unresolved externals
I`ve uploaded 2 versions of the code: Visual C++ 6 Workspace: http://www.ram-interactive.co.uk/LinkListProject.zip Single .h and .cpp files:http://www.ram-interactive.co.uk/LinkList.zip ** Sorry for post looking odd, decided to upload code after posting originally **
[ rIK ][ rik@ram-solutions.co.uk ]
Advertisement
You haven't included a library you need. However, you cut out the error messages for some unknown reason so no one can tell you what you need to link with your project.
Even though your code snipplet...isn't...yeah...

That error means that you haven't included that library required to compile the code..
Both links give a HTTP 404 (File not found) error.

The error message says that the compiler can't find the implementation of the default constructor and the destructor. Make sure that they are either implemented in the header, or you have LinkList.cpp added to your project.
You can just post the code here using

[source]
[/source]

tags surrounding your code.
God I hate it when this happens, but found (I think) the source of my problem.
The .h file has a constructor and a destructor defined, commenting out these 2 lines lets the program run.

The problem then is that the .h file was "given" to me from class, and the tasks we have are to build a cpp file based upon the .h we have been given.

I`m not sure if commenting them out is allowed, so I`m in a catch 22 if the answer is "remove these" :)

*** Links fixed ***
[ rIK ][ rik@ram-solutions.co.uk ]
The problem is that you declare the constructor and destructor, but don't implement them. So the compiler can't find the functions.

Add this to linklist.cpp:
LinkList::LinkList(){   head = NULL;   numInList = 0;}LinkList::~LinkList(){   // Cleanup code here}

I've left the code for the destructor for you (since its an assignment), but you wanna delete the node and move to the next one while the next node is not NULL. However, remember that you can't delete the node and then get the "next" member of the node. Ok, I think I've hinted enough ;)
Ahhh, feck!
I guess we were all as crap as me once :)

I don`t want my assignment done for me, but I spent about 30 mins with this problem (agh!) and now I can create an instance of my class, I can carry on coding.

Cheers for the real quick replies too, much appreciated! :)
[ rIK ][ rik@ram-solutions.co.uk ]

This topic is closed to new replies.

Advertisement