473,789 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Weird Errors

12 New Member
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>implementatio n.cpp
1>Linking...
1>actualmain.ob j : error LNK2019: unresolved external symbol "public: __thiscall SortedList<floa t>::SortedList< float>(void)" (??0?$SortedLis t@M@@QAE@XZ) referenced in function _main
1>actualmain.ob j : error LNK2019: unresolved external symbol "public: __thiscall SortedList<char >::SortedList<c har>(void)" (??0?$SortedLis t@D@@QAE@XZ) referenced in function _main
1>C:\projectscp p\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 1974
Savage
1,764 Recognized Expert Top Contributor
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
TamaThps
12 New Member
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
2787
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 genwin.sqc file. I am using Setting the lib and include path: set INCLUDE=C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\include;C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Samples\esqlc;%include%
2
1465
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; limit1=(floor(limit1*100))/100;
2
1531
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 datalist after me. and intellesense works for the control datalist2. Build\Rebuild all reports a failure, but does not specify the errors. Running the page results in a message box 'There were build errors. Would you like to continue and run the last...
0
2064
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 "Unrecognized tag prefix or device filter 'asp'" on the third line shown below... <head runat="server">
28
13207
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 yow But, in firefox, for same html, getting this:
20
2172
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 software. The hardware has been tested several times. Viruses, trojans and so on: clean for sure. The problem is that .mdb files (_only .mdb files_) often don't open, are very slow, or even get crashed and corrupted. The weird is that even copying them...
1
1497
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 http://pastebin.com/m3859cf40 It´s really a lot... Someone got ideas?
16
1777
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") txtWfCost.Text = Format(mRackc - mDisc + mWfEC, "0.#####0")
6
1875
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 box: (errored code) Select Case ComboBox2.text Case Is ="Execute Program" 'code to execute program here Case Is ="Other Command that executes code at a certain time" ' code below the same as above except that it works But not my first(this...
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3700
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.