"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
- #define MAX_ITEMS 20
- template<class ItemType>
- class SortedList
- {
- private:
- int length;
- ItemType values[MAX_ITEMS];
- int currentPos;
- public:
- SortedList( ); // default constructor: lenght=0, currentPos=-1
- void MakeEmpty(); // let length=0
- void InsertItem(ItemType x); // insert x into the list
- void DeleteItem(ItemType x); // delete x from the list
- bool IsFull( ); // test if the list is full
- int LengthIs( ); // return length
- void RetrieveItem(ItemType &x, bool &found); // retrieve x from the list, the
- // boolean result is stored in found
- void ResetList( ); // currentPos=-1
- void GetNextItem(ItemType &x); // get the next element from the list with
- // respect to the currentPos
- int numCharElement();
- int numFloatElement();
- };
Expand|Select|Wrap|Line Numbers
- #include <fstream>
- #include <iostream>
- #include "part2.h"
- using namespace std;
- template<class ItemType>
- SortedList<ItemType>::SortedList()
- {
- length = 0;
- currentPos= -1;
- }
- template<class ItemType>
- void SortedList<ItemType>::MakeEmpty()
- {
- length=0;
- }
- template<class ItemType>
- void SortedList<ItemType>::InsertItem(ItemType x)
- {
- int midpoint;
- int first=0;
- int last= length-1;
- midpoint = (first+last)/2;
- bool moreToSearch = (first <= last);
- found = false;
- while(moreToSearch)
- {
- switch(x.comparedTo(values[location]))
- {
- case LESS: //search in 1st half
- moreToSearch = (first <= last);
- last= midpoint-1;
- break;
- case GREATER:
- location ++;
- moreToSearch=(location<length);
- break;
- }
- }
- for (int index=length; length>location; index--)
- {
- values[index]= values[index-1];
- }
- values[location] =x;
- length++;
- }
- template<class ItemType>
- void SortedList<ItemType>::DeleteItem(ItemType x)
- {
- int midpoint;
- int first=0;
- int last= length-1;
- midpoint= (first+last)/2
- bool moreToSearch = (first <= last);
- found = false;
- while(moreToSearch)
- {
- switch(x.comparedTo(values[location]))
- {
- case LESS: //search in 1st half
- moreToSearch = (first <= last);
- last= midpoint-1;
- break;
- case GREATER:
- location ++;
- moreToSearch=(location<length);
- break;
- }
- }
- for (int index=length; length>location; index--)
- {
- values[index]= values[index-1];
- }
- values[location] =x;
- length++;
- }
- template<class ItemType>
- void SortedList<ItemType>::RetrieveItem(ItemType &x, bool &found)
- {
- int midpoint;
- int first=0, last=length-1;
- bool moreToSearch= (first <= last);
- found= false;
- while(moreToSearch && !found)
- {
- midpoint=(first+last)/2
- switch(x.comparedTo(values[index]))
- {
- case LESS: //search in 1st half
- moreToSearch= (first <= last);
- last= midpoint-1;
- break;
- case GREATER; //Search in 2nd half
- first= midpoint+1;
- moreToSearch = (first <=last);
- break;
- case EQUAL; //x has been found
- found= true;
- break;
- }
- }
- }
- template<class ItemType>
- int SortedList<ItemType>::LengthIs()
- {
- return length;
- }
- template<class ItemType>
- void SortedList<ItemType>::ResetList()
- {
- currentPos= -1;
- }
- template<class ItemType>
- bool SortedList<ItemType>::IsFull()
- {
- if (length < 19)
- return false;
- else
- return true;
- }
- template<class ItemType>
- void SortedList<ItemType>::GetNextItem(ItemType &x)
- {
- currentPos++;
- item = values [currentPos];
- }
- template<class ItemType>
- int SortedList<ItemType>::numCharElement()
- {
- indata.open("char.dat");
- int i=0;
- int size=0;
- char values[20];
- while (indata.eof()) // write or read data from indatac into values
- {
- indata >> values[i];
- i++;
- size++; // this will count how many values there are in the array
- }
- for(i=0; i<size; i++)//just a test to see if it put the values in the array
- {
- cout<<values[i]<<endl;
- }
- for (int i=0; i< size; i++)
- {
- a.InsertItem (values[i]); //and insterts each element into the list
- }
- cout << "There are "<< size << " items in the char array" << endl;
- indata.close();
- return size;
- }
- template<class ItemType>
- int SortedList<ItemType>::numFloatElement()
- {
- int i=0;
- int size=0;
- indata.open("float.dat");
- float values[20];
- while (!indata.eof()) // write or read data from indatac into values
- {
- indata >> values[i];
- i++;
- size++; // this will count how many values there are in the array
- }
- for(i=0; i<size; i++)//just a test to see if it put the values in the array
- {
- cout<<values[i]<<endl;
- }
- for (int i=0; i< size; i++)
- {
- b.InsertItem (values[i]); //and insterts each element into the list
- }
- cout << "There are "<< size << " items in the char array" << endl;
- indata.close();
- return size;
- }
Expand|Select|Wrap|Line Numbers
- #include "part2.h"
- #include <fstream>
- #include <iostream>
- using namespace std;
- int main()
- {
- ifstream indata;
- SortedList<char> a;
- //a.numCharElement();
- SortedList<float> b;
- //b.numFloatElement();
- return 0;
- }
Thanks a lot.