473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Weird Errors

Hi, I'm using visual studio 2008 and normally when I get an error it shows what line it is on and which file etc. The error I'm getting I don't know how to solve or even what the problem is. This is the whole output when I try to run the program.
"1>------ Build started: Project: corysid, Configuration: Debug Win32 ------
1>Compiling...
1>implementation.cpp
1>Linking...
1>actualmain.obj : error LNK2019: unresolved external symbol "public: __thiscall SortedList<float>::SortedList<float>(void)" (??0?$SortedList@M@@QAE@XZ) referenced in function _main
1>actualmain.obj : error LNK2019: unresolved external symbol "public: __thiscall SortedList<char>::SortedList<char>(void)" (??0?$SortedList@D@@QAE@XZ) referenced in function _main
1>C:\projectscpp\corysid\Debug\corysid.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://c:\projectscpp\corysid\corysid\Debug\BuildLog.htm"
1>corysid - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========="

I'm using a class template, and it seems it cannot access parts of the class when I make an instance of the class?

Here's the code if that helps
.h file:
Expand|Select|Wrap|Line Numbers
  1. #define MAX_ITEMS  20
  2.  
  3. template<class ItemType>
  4. class SortedList
  5.        private:
  6.         int length;
  7.         ItemType values[MAX_ITEMS];
  8.         int currentPos;
  9.        public:
  10.          SortedList( );  // default constructor: lenght=0, currentPos=-1
  11.          void MakeEmpty();    // let length=0
  12.          void InsertItem(ItemType x);   // insert x into the list     
  13.          void DeleteItem(ItemType x);  // delete x from the list
  14.          bool IsFull( );        // test if the list is full
  15.          int LengthIs( );   // return length
  16.          void RetrieveItem(ItemType &x, bool &found);            // retrieve x from the list, the 
  17.                                                                 // boolean result is stored in found
  18.          void ResetList( );  // currentPos=-1
  19.          void GetNextItem(ItemType &x);                        // get the next element from the list with 
  20.                                                             // respect to the currentPos
  21.          int numCharElement();
  22.          int numFloatElement();
  23. };
Implementation:
Expand|Select|Wrap|Line Numbers
  1. #include <fstream>
  2. #include <iostream>
  3. #include "part2.h"
  4. using namespace std;
  5.  
  6.  
  7. template<class ItemType>
  8. SortedList<ItemType>::SortedList()
  9. {
  10.     length = 0;
  11.     currentPos= -1;
  12. }
  13.  
  14. template<class ItemType>
  15. void SortedList<ItemType>::MakeEmpty()
  16. {
  17.     length=0;
  18. }
  19.  
  20. template<class ItemType>
  21. void SortedList<ItemType>::InsertItem(ItemType x)
  22. {
  23.  
  24.     int midpoint;
  25.     int first=0;
  26.     int last= length-1;
  27.     midpoint = (first+last)/2;
  28.  
  29.     bool moreToSearch = (first <= last);
  30.     found = false;
  31.     while(moreToSearch)
  32.     {
  33.         switch(x.comparedTo(values[location]))
  34.         {
  35.         case LESS:    //search in 1st half
  36.             moreToSearch = (first <= last);
  37.             last= midpoint-1;
  38.             break;
  39.         case GREATER:
  40.                 location ++;
  41.                 moreToSearch=(location<length);
  42.                 break;
  43.         }
  44.     }
  45. for (int index=length; length>location; index--)
  46. {    
  47.     values[index]= values[index-1];
  48. }
  49.     values[location] =x;
  50.     length++;
  51.  
  52. }
  53.  
  54.  
  55. template<class ItemType>
  56. void SortedList<ItemType>::DeleteItem(ItemType x)
  57. {
  58.     int midpoint;
  59.     int first=0;
  60.     int last= length-1;
  61.     midpoint= (first+last)/2
  62.  
  63.     bool moreToSearch = (first <= last);
  64.     found = false;
  65.     while(moreToSearch)
  66.     {
  67.         switch(x.comparedTo(values[location]))
  68.         {
  69.         case LESS:    //search in 1st half
  70.             moreToSearch = (first <= last);
  71.             last= midpoint-1;
  72.             break;
  73.         case GREATER:
  74.                 location ++;
  75.                 moreToSearch=(location<length);
  76.                 break;
  77.         }
  78.     }
  79. for (int index=length; length>location; index--)
  80. {    
  81.     values[index]= values[index-1];
  82. }
  83.     values[location] =x;
  84.     length++;
  85.  
  86. }
  87.  
  88. template<class ItemType>
  89. void SortedList<ItemType>::RetrieveItem(ItemType &x, bool &found)
  90. {
  91.     int midpoint;
  92.     int first=0, last=length-1;
  93.     bool moreToSearch= (first <= last);
  94.     found= false;
  95.     while(moreToSearch && !found)
  96.     {
  97.         midpoint=(first+last)/2
  98.         switch(x.comparedTo(values[index]))
  99.         {
  100.         case LESS:        //search in 1st half
  101.             moreToSearch= (first <= last);
  102.             last= midpoint-1;
  103.             break;
  104.         case GREATER;    //Search in 2nd half
  105.             first= midpoint+1;
  106.             moreToSearch = (first <=last);
  107.             break;
  108.         case EQUAL;        //x has been found
  109.             found= true;
  110.             break;
  111.         }
  112.     }
  113. }
  114.  
  115. template<class ItemType>
  116. int SortedList<ItemType>::LengthIs()
  117. {
  118.     return length;
  119. }
  120.  
  121. template<class ItemType>
  122. void SortedList<ItemType>::ResetList()
  123. {
  124.     currentPos= -1;
  125. }
  126.  
  127. template<class ItemType>
  128. bool SortedList<ItemType>::IsFull()
  129. {
  130.     if (length < 19)
  131.         return false;
  132.     else
  133.         return true;
  134. }
  135.  
  136. template<class ItemType>
  137. void SortedList<ItemType>::GetNextItem(ItemType &x)
  138. {
  139.     currentPos++; 
  140.     item = values [currentPos]; 
  141. }
  142.  
  143. template<class ItemType>
  144. int SortedList<ItemType>::numCharElement()
  145. {
  146.     indata.open("char.dat");
  147.  
  148.     int i=0; 
  149.     int size=0;
  150.  
  151.     char values[20];
  152.     while (indata.eof())        // write or read data from indatac into values
  153.     {    
  154.     indata >> values[i];            
  155.     i++;
  156.     size++;                    // this will count how many values there are in the array
  157.     }    
  158.  
  159.     for(i=0; i<size; i++)//just a test to see if it put the values in the array
  160.     {
  161.     cout<<values[i]<<endl;
  162.     }
  163.  
  164.  
  165.     for (int i=0; i< size; i++)    
  166.     {            
  167.  
  168.     a.InsertItem (values[i]);        //and insterts each element into the list
  169.     }
  170.  
  171.  
  172.     cout << "There are "<< size << " items in the char array" << endl;        
  173.  
  174.  
  175.     indata.close();
  176.     return size;
  177.  
  178.  
  179. }
  180.  
  181.  
  182.  
  183. template<class ItemType>
  184. int SortedList<ItemType>::numFloatElement()
  185. {
  186.     int i=0; 
  187.     int size=0;
  188.     indata.open("float.dat");
  189.  
  190.     float values[20];
  191.     while (!indata.eof())        // write or read data from indatac into values
  192.     {    
  193.     indata >> values[i];            
  194.     i++;
  195.     size++;                    // this will count how many values there are in the array
  196.     }    
  197.  
  198.     for(i=0; i<size; i++)//just a test to see if it put the values in the array
  199.     {
  200.     cout<<values[i]<<endl;
  201.     }
  202.  
  203.  
  204.     for (int i=0; i< size; i++)    
  205.     {                                    
  206.     b.InsertItem (values[i]);        //and insterts each element into the list
  207.     }
  208.  
  209.  
  210.     cout << "There are "<< size << " items in the char array" << endl;        
  211.  
  212.  
  213.     indata.close();
  214.     return size;
  215.  
  216.  
  217. }
Main function:
Expand|Select|Wrap|Line Numbers
  1. #include "part2.h"
  2. #include <fstream>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9. ifstream indata;
  10.  
  11. SortedList<char> a;
  12. //a.numCharElement();
  13.  
  14. SortedList<float> b;
  15. //b.numFloatElement();
  16. return 0;
  17. }
The code is supposed to call those 2 template functions and populate an array in sorted order. But I need to get past those weird errors to even try and debug the logic errors etc.

Thanks a lot.
Mar 14 '09 #1
2 1949
Savage
1,764 Expert 1GB
When you are coding templates both definition and implementation must be in the same file.There are ways around it, but they are not worth it.
Mar 15 '09 #2
Thank you sir. I should be able to get it working now
Mar 15 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: amit | last post by:
I am trying to compile the sample program genwin.sqc, using nsqlprep which is used to precompile embedded sql in C. I am getting weird errors and that is because windows.h is included in the...
2
by: ai lian | last post by:
The code is as the following: { double limit= 0.02*33.00; double limit1= 0.06*11.00; double limit2= 0.03*22.00; double limit3= 0.01*66.00; limit=(floor(limit*100))/100;...
2
by: Lisa Calla | last post by:
My aspnet web was working perfectly fine, then I added a second datalist to a page. The datalist can be formatted in the designer and everything looks fine. In the codefile, I can see the...
0
by: Alan Silver | last post by:
Hello, I have two weird problems here. I have a master page file that works absolutely fine. When I load it up in VWD, I get a couple of weird (to me) errors. First, I get the error...
28
by: entfred | last post by:
I have the following line of html: &nbsp;&nbsp1234&nbsp;&nbsp;&nbsp;&nbsp;&nbspabc&nbsp;&nbsp;&nbspyow In Internet Explorer 6.0, the columns look ok using the above html: 1234 abcd ...
20
by: ongaro.admin | last post by:
Hi, I'm experiencing a strange problem with .mdb files. We have two buildings connected by optical fiber (a single LAN). Everything works perfect with any file, any size, any application...
1
by: Jonas Schneider | last post by:
Hi guys, I´m experiencing weird error messages while installing MySQL-python with easy_install... I have no idea where the errors come from. Read the whole output at...
16
by: Bill Nguyen | last post by:
I'm running into a very weird problem regarding subtraction. Subtraction behaves as if it's an addition in the below sub txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0") ...
6
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
i need help with a combo box and this same code works on my first tab with a combo box. The error or problem i have is this code causes an index out of range error when i run it on my second combo...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.