Error 1 error LNK2019: unresolved external symbol "public: __thiscall vector::my_vector<int>::~my_vector<int>(void)" (??1?$my_vector@H@vector@@QAE@XZ) referenced in function _main test.obj
Error 2 error LNK2019: unresolved external symbol "public: __thiscall vector::my_vector<int>::my_vector<int>(void)" (??0?$my_vector@H@vector@@QAE@XZ) referenced in function _main test.obj
Error 3 fatal error LNK1120: 2 unresolved externals C:\Users...\Documents\Visual Studio 2008\Projects\Iterator and Generic Vector Container\Debug\Iterator and Generic Vector Container.exe
if i have the code below and close my_vector<int> v1 then their are no errors which leads me to believe the errors are in my_vector class. and it probably deals with the begin() and end() in my_vector.cpp class not having a template type. That's what i think. Any help appreciated thanks again.
test program(test.cpp)
#include "my_vector.h"
#include "my_vector_iterator.h"
using namespace vector;
int main()
{
my_vector<int> v1;
vector_iterator<int> itr;
return 0;
}
my_vector.h
//my_vector.h
#ifndef MY_VECTOR_H
#define MY_VECTOR_H
#include "my_vector_iterator.h"
#include "my_vector_iterator.cpp"
namespace vector
{
template<class DT>
class my_vector
{
public:
//destructor
~my_vector();
//copy constructor
my_vector(const my_vector<DT>& b);
//constructor that create an empty vector
my_vector();
/*constructor that create an vector with capacity specified
as a parameter but doesn't assign values to each element
in the vector*/
my_vector(unsigned int intial_Size);
/*constructor that create a vector with capacity specified
as a parameter and assign all the elements the value
specified*/
my_vector(unsigned int intial_Size, DT assign);
//overloaded assignement operator
my_vector& operator=(const my_vector<DT>& a);
//returns total number of elements in an array
int capacity();
//returns number of elements in array that are filled
int size();
//adds an value at next position in vector
void push_back(DT user_number);
//prints out the vector that contains the numbers recursively
void show_vector(unsigned int siz);
//deletes the number from last element that stores a number
void pop_back();
//return value at the index specified by user
DT at(size_t arrayindex);
//return value at index specified by user
DT operator[](size_t array_index);
//return a iterator to first value in container
vector_iterator<DT> begin();
//return a iterator to value after one in container
vector_iterator<DT> end();
private:
//array to store numbers
DT* numbers;
//total amount of elements that can be stored in array
int capacit;
//number of elements that are filled
int siz;
};
}
#endif
my_vector.cpp
//Implementation of functions in my_vector.h
#include "my_vector.h"
#include "my_vector_iterator.h"
namespace vector
{
template<class DT>
my_vector<DT>::~my_vector()
{
delete[] numbers;
}
template<class DT>
my_vector<DT>::my_vector(const my_vector<DT>& b)
{
capacit=b.capacit;
numbers=new DT[capacit];
siz=b.siz;
for(long j=0; j<siz; j++)
{
numbers[j]=b.numbers[j];
}
}
template<class DT>
my_vector<DT>& my_vector<DT>::operator=(const my_vector<DT>& a)
{
capacit=a.capacit;
siz=a.siz;
if(this!=&a)
{
DT* temp;
temp=a.numbers;
delete[] numbers;
numbers=new DT[capacit];
for(long g=0; g<siz; g++)
{
numbers[g]=temp[g];
}
}
return *this;
}
template<class DT>
my_vector<DT>::my_vector()
{
siz=0;
capacit=0;
numbers=NULL;
}
template<class DT>
my_vector<DT>::my_vector(unsigned int intial_Size)
{
siz=0;
capacit=intial_Size;
numbers=new DT[capacit];
}
template<class DT>
my_vector<DT>::my_vector(unsigned int intial_Size,DT assign)
{
siz=0;
capacit=intial_Size;
numbers=new DT[capacit];
for(long b=0; b<capacit; b++)
{
numbers[b]=assign;
siz++;
}
}
template<class DT>
DT my_vector<DT>::at(size_t arrayindex)
{
return numbers[arrayindex];
}
template<class DT>
DT my_vector<DT>::operator [](size_t arra)
{
return numbers[arra];
}
template<class DT>
void my_vector<DT>::push_back(DT user_number)
{
DT* temp;
//empty vector
if(capacit==0)
{
capacit=capacit+1;
numbers=new DT[capacit];
numbers[0]=user_number;
siz++;
}
//last element doesn't contain a value
else if(siz!=capacit)
{
numbers[siz]=user_number;
siz++;
}
//last element contain a value so must expand the array
else if(siz==capacit)
{
temp=numbers;
numbers=NULL;
delete[] numbers;
numbers=NULL;
capacit=capacit*2;
numbers=new DT[capacit];
for(long a=0; a<siz; a++)
{
numbers[a]=temp[a];
}
delete[] temp;
numbers[siz]=user_number;
siz++;
}
}
template<class DT>
int my_vector<DT>::capacity()
{
return capacit;
}
template<class DT>
int my_vector<DT>::size()
{
return siz;
}
template<class DT>
void my_vector<DT>::pop_back()
{
siz--;
}
template<class DT>
void my_vector<DT>::show_vector(unsigned int siz)
{
if(siz!=1)
{
show_vector(siz-1);
}
cout<<numbers[siz-1]<<"\n";
}
template<class DT>
vector_iterator<DT> my_vector<DT>::begin()
{
vector_iterator c;
c.cursor=numbers;
c.index=0;
return c;
}
template<class DT>
vector_iterator<DT> my_vector<DT>::end()
{
vector_iterator c;
c.cursor=numbers;
c.index=siz;
return c;
}
}
my_vector_iterator.h
#ifndef MY_VECTOR_ITERATOR_H
#define MY_VECTOR_ITERATOR_H
namespace vector
{
template<class DT>
class vector_iterator
{
public:
//default constructor
vector_iterator();
//increment the pointer
void operator++();
//return value by derefencing
DT operator*();
//checks on
bool operator!=(vector_iterator<DT>* b);
private:
//used to get the data in the counter
DT* cursor;
//counter which says the current position
int index;
};
}
#endif
my_vector.cpp
#include "my_vector_iterator.h"
namespace vector
{
template<class DT>
vector_iterator<DT>::vector_iterator()
{
cursor=0;
index=0;
}
template<class DT>
void vector_iterator<DT>::operator ++()
{
index++;
}
template<class DT>
DT vector_iterator<DT>::operator *()
{
return cursor[index];
}
template<class DT>
bool vector_iterator<DT>::operator !=(vector_iterator<DT> *b)
{
if(this->cursor==b->cursor)
{
return true;
}
else
{
return false;
}
}
}