C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-03-2001, 01:49 PM   #1
Registered User
 
Join Date: Sep 2001
Posts: 7
Template Class for Linked List

Hello,

This is for an assignment I am trying to complete. For a previous assignment, I had to create a linked list class for integers. I was able to get that working fine. This assignment is to convert the linked list class into a template so that it can be a linked list of anything.

I figured the best way to start was to take the linked list class for intergers, scale it back to just a few methods, and then convert it to a template.

I converted my two classes. One was a Node class(which had a data member and a pointer to Node) and the other was Linked List (which had the pointer to the head node, a int member to keep track of the number of nodes in the list, and methods to pop, push, insert nodes). For the template version of the LinkedList class I just started with the push method and the constructors and destructors.

With just the .h and .cpp files for the classes defined, the compiling works without error. But when I try to establish a variable of type LinkedList in a harness program I receive the following errors, but am uncertain how to resolve.

--------------------Configuration: Assn5 Template Linked List Class - Win32 Debug--------------------
Compiling...
Assn5_Linked List Class.cpp
LinkedList.cpp
Linking...
Assn5_Linked List Class.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall LinkedList<int>::~LinkedList<int>(void)" (??1?$LinkedList@H@@UAE@XZ)

Assn5_Linked List Class.obj : error LNK2001: unresolved external symbol "public: __thiscall LinkedList<int>::LinkedList<int>(void)" (??0?$LinkedList@H@@QAE@XZ)

Debug/Assn5 Template Linked List Class.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

Assn5 Template Linked List Class.exe - 3 error(s), 0 warning(s)


~~~~~~~~~~~~~~~~~~~~~~~

I have attached the code I am using ...
Attached Files
File Type: zip cprogrammingsite.zip (4.0 KB, 41 views)
pecymanski is offline   Reply With Quote
Old 12-03-2001, 02:10 PM   #2
zen
of Zen Hall
 
zen's Avatar
 
Join Date: Aug 2001
Posts: 1,007
You'll either have to include the cpp file in your driver file or move all the template methods into the header file(a more common method). The compiler and not just the linker needs to be able to see these methods in the same file as the template instance to instantiate the template object.
__________________
zen

Last edited by zen; 12-03-2001 at 02:16 PM.
zen is offline   Reply With Quote
Old 12-04-2001, 09:07 PM   #3
Registered User
 
Join Date: Sep 2001
Posts: 7
Thanks, worked great
pecymanski is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pleas take a look & give a critique sh3rpa C++ Programming 14 10-19-2007 10:01 PM
Templates that only accept certain types and class having a template as friend Boksha C++ Programming 8 07-24-2006 08:14 AM
Dikumud maxorator C++ Programming 1 10-01-2005 06:39 AM
How can I traverse a huffman tree carrja99 C++ Programming 3 04-28-2003 05:46 PM
Contest Results - May 27, 2002 ygfperson A Brief History of Cprogramming.com 18 06-18-2002 01:27 PM


All times are GMT -6. The time now is 04:24 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22