Jump to content
  • Advertisement
Sign in to follow this  
rIKmAN

Cant create instance of class...

This topic is 4998 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 **

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ***

Share this post


Link to post
Share on other sites
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 ;)

Share this post


Link to post
Share on other sites
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! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!