hi all i have big problem can you help me please , i have a dynamic list
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
//ordlist.h
#ifndef ORDLIST_H
#define ORDLIST_H
#include<iostream>
using namespace std;
template <class T>
class ordlist
{
public:
ordlist(int size1);
~ordlist();
void insert(const ordlist& insertitem);
void remove(const ordlist& removeitem);
void removeat(int location);
int search(const ordlist& item);
bool isEmpty();
bool isFull();
ordlist(const ordlist<T>&);
const ordlist<T>& operator=(const ordlist<T>&);
void print();
protected:
int max_size;
int legnth;
T *list;
};
#endif
|
-----------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
//ordlist.cpp
#include"ordlist.h"
template <class T>
ordlist<T>::ordlist(int size1)
{
if(size1<0)
{cout<<"The size must be positive"<<endl;
max_size=100;}
else
max_size=size1;
legnth=0;
list=new T[max_size];
}
template <class T>
ordlist<T>::~ordlist()
{
delete [] list;
}
template <class T>
void ordlist<T>::insert(const ordlist<T>& insertitem)
{
int location;
if(legnth==0)
list[legnth++]=insetitem;
else if(legnth==max_size)
cout<<"list is full"<<endl;
else
{
loc=search(insertitem);
if(location=-1)
list[legnth++] =insertitem;
else
cout<<"is in list"<<endl;
}
}
template <class T>
void ordlist<T>::remove(const ordlist& removeitem)
{int location;
if(legnth==0)
cout<<"can't delete from an empty array"<<endl;
else
{location=search(removeitem);
if(location!=-1)
removeat(location);
else
cout<<"The item is not found"<<endl;}
}
template <class T>
void ordlist<T>::removeat(int location)
{
if(location<0 || location>=legnth)
cout<<"cannot delete"<<endl;
else
{for(int i=location;i<legnth-1;i++)
list[i]=list[i+1];
legnth--;
}
}
template <class T>
int ordlist<T>::search(const ordlist& item)
{
int location;
bool found=false;
for(location=0;location<legnth;location++)
if(list[location]==item)
{
found=true;
break;
}
if(found)
return location;
else
return -1;
}
template <class T>
bool ordlist<T>::isEmpty()
{
return(legnth==0);
}
template <class T>
bool ordlist<T>::isFull()
{
return(legnth==max_size);
}
template <class T>
ordlist<T>::ordlist(const ordlist<T>&a)
{
max_size=a.max_size;
legnth=a.legnth;
list= new T[max_size];
for(int i=0;i<legnth;i++)
list[i]=a.list[i];
}
template <class T>
const ordlist<T>& ordlist<T>::operator=(const ordlist<T>&a)
{
if(this!=&a)
{
delete []list;
max_size=a.max_size;
legnth=a.legnth;
list=new T[max_size];
for(int i=0;i<legnth;i++)
list[i]=a.list[i];
}
return *this;
}
template <class T>
void ordlist<T>::print()
{
for(int i=0;i<legnth;i++)
cout<<list[i]<<" "<<endl;
}
|
-------------------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include"ordlist.h"
//main.cpp
#include<iostream>
using namespace std;
int main()
{
ordlist<int>ob(4);
ob.insert(1);
ob.insert(1);
ob.insert(1);
ob.insert(1);
ob.print();
return 0;
}
|
and this is error
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall ordlist<int>::print(void)" (?print@?$ordlist@H@@QAEXXZ) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "public: __thiscall ordlist<int>::~ordlist<int>(void)" (??1?$ordlist@H@@QAE@XZ) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall ordlist<int>::insert(class ordlist<int> const &)" (?insert@?$ordlist@H@@QAEXABV1@@Z) referenced in function _main
main.obj : error LNK2019: unresolved external symbol "public: __thiscall ordlist<int>::ordlist<int>(int)" (??0?$ordlist@H@@QAE@H@Z) referenced in function _main
c:\users\abo abbas\documents\visual studio 2010\Projects\hw5555\Debug\hw5555.exe : fatal error LNK1120: 4 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-----------------------------
help me and thanks