hy
i wrote a list class , i tested it for int values but now i want to make it a templet
but somting is not wright with the function declarations
i got this erorr
error LNK2019: unresolved external symbol "public: int __thiscall vector_eu<int>::erace(int,int)" (?erace@?$vector_eu@H@@QAEHHH@Z) referenced in function _wmain test vector eu.obj
here ar the declarations in define element.h
#include <iostream>
using namespace std;
template <typename tip>
class element
{public:
tip val;
int initializat; /// arata daca un element e initializat sau nu
element<tip>* point_front;
element<tip>* point_back;
};
template <typename tip>
class vector_eu
{
public:
vector_eu(); //constructor
int push_bak(tip);//adauga un element in coada vectorului push_bak(element)
int insert(tip,int);//adauga un element intr-un loc specificat insert(element,pozitie)
int erace(int);//sterge un element dintr-o pozitie specificata erace(pozitie)
int erace(int,int);//sterge un nr de caractere incepand cu o pozitie specificata erace(pozitie,nr_de_elemente)
int clear(void); //sterge tot vectorul
int get(int);
private:
element<tip>* primul_element;
int nr_de_elemente;
element<tip>* ultimul_element;
element<tip>* get_addres(int);
};
and here is the the implementations
#include "stdafx.h"
#include <iostream>
#include <string>
#include "define element.h"
using namespace std;
void error(string s)
{
cout<<s<<endl;
}
template <typename tip>
inline
vector_eu<tip>::vector_eu()
{
this->nr_de_elemente=0;
this->primul_element=new element<tip>; // creaza primul element vid
this->primul_element->initializat=0;
this->primul_element->point_back=0; // pointerul spre elemntul precedent pt primul elemnt este 0
this->primul_element->point_front=0;// daca pointerul spre urmatorul element este 0 --> nu exita
this->ultimul_element=this->primul_element;
}
template <typename tip>
inline
int vector_eu<tip>::push_bak(tip val)
{
if((this->nr_de_elemente)==0)
{
(this->primul_element)->initializat=1;
(this->primul_element)->val=val;
++(this->nr_de_elemente);
return 1;
}
else
{
element * temp=new element;
temp->initializat=1;
temp->val=val;
temp->point_front=0;
temp->point_back=(this->ultimul_element);
(this->ultimul_element)->point_front=temp;
(this->ultimul_element)=temp;
++(this->nr_de_elemente);
return 1;
}
}
template <typename tip>
inline
element<tip>* vector_eu<tip>::get_addres(int n) /// iterator incepe de la 0
{
if (this->nr_de_elemente==0)
{
error("nu exista elemente");
return 0;
}
else
{ if(n<this->nr_de_elemente)
{
if(n==0) return this->primul_element;
else
{
if(n<0){ error("iterator<0");return 0;}
else
{
element*temp=this->primul_element;
while(n>0)
{
temp=temp->point_front;
--n;
}
return temp;
}
}
}
else
{
error("iterator>nr_de_elemente");
}
}
}
template <typename tip>
inline
int vector_eu<tip>::get(int n)
{
if(this->nr_de_elemente>n)
{
if(n>-1)
{
element * temp =get_addres(n);
return temp->val;
}
else {
error("iterator<0");
return 0;
}
}
else {
error("iterator>nr_de_elemente");
return 0;
}
}
template <typename tip>
inline
int vector_eu<tip>::clear(void)
{
if(this->nr_de_elemente!=0)
{
if(this->nr_de_elemente>0)
{
element* temp=this->ultimul_element;
while(this->nr_de_elemente>1)
{
temp=temp->point_back;
delete (temp->point_front);
--(this->nr_de_elemente);
}
temp->point_front=0;
temp->initializat=0;
temp->val=0;
(this->ultimul_element)=(this->primul_element);
(this->nr_de_elemente)=0;
return 1;
}
else {error("nr_de_elemente<0");return 0;}
}
else
return 1;
}
template <typename tip>
inline
int vector_eu<tip>::erace(int n)
{
if(n<this->nr_de_elemente)
{
if(n>-1)
{
if(n==0)
{
if(this->nr_de_elemente==1)
{
this->clear();
}
else
{
element *temp=this->primul_element;
this->primul_element=(this->primul_element)->point_front;
(this->primul_element)->point_back=0;
delete temp;
--(this->nr_de_elemente);
return 1;
}
}
else{
if((n+1)==this->nr_de_elemente)
{
element * temp=this->ultimul_element;
((this->ultimul_element)->point_back)->point_front=0;
(this->ultimul_element)=(this->ultimul_element)->point_back;
delete temp;
--(this->nr_de_elemente);
return 1;
}
else
{
element * temp=get_addres(n);
(temp->point_back)->point_front=temp->point_front;
(temp->point_front)->point_back=temp->point_back;
delete temp;
--(this->nr_de_elemente);
return 1;
}
}
}
else error("iterator<0");
}
else error("iterator>nr_de_elemente");
return 0;
}
template <typename tip>
inline
int vector_eu<tip>::erace(int n, int r) ///!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
{
if(n<0)
{
error("iterator poz<0");
return 0;
}
else
if(r<0)
{
error("iterator lungime<0");
return 0;
}
else
if(r==0)
{
error("iterator lungime = 0");
}
else
if((n+r)>(this->nr_de_elemente))
{
error("depaseste dimensiunea");
return 0;
}
else
{
if(r==1)
{
erace(n);
return 1;
}
else
if(n==0)
{
if(r==(this->nr_de_elemente))
{
this->clear();
return 1;
}
else
{
element * temp=(this->primul_element);
for(int i=0;i<r;++i)
{
temp=(temp->point_front);
delete (temp->point_back);
}
(this->primul_element)=temp;
(this->primul_element)->point_back=0;
this->nr_de_elemente-=r;
return 1;
}
}
else
{
if((n+r)==(this->nr_de_elemente))
{
element *temp=get_addres(n);
(this->ultimul_element)=temp->point_back;
(this->ultimul_element)->point_front=0;
for(int i=1;i<r;++i)
{
temp=temp->point_front;
delete temp->point_back;
}
delete temp;
this->nr_de_elemente-=r;
return 1;
}
else
{
element *temp=get_addres(n);
element *temp_2=(get_addres(n-1));
element *temp_3=get_addres(n+r);
temp_2->point_front=temp_3;
temp_3->point_back=temp_2;
for(int i=1;i<r;++i)
{
temp=temp->point_front;
delete temp->point_back;
}
delete temp;
this->nr_de_elemente-=r;
return 1;
}
}
}
}
template <typename tip>
inline
int vector_eu<tip>::insert(tip val, int n)
{
if((n==0)&&(this->nr_de_elemente==0))
this->push_bak(val);
else
if(n>this->nr_de_elemente)
{
error("iterator>nr_de_elemente");
return 0;
}
else
if(n<0)
{
error("iterator<0");
return 0;
}
else
if(n==this->nr_de_elemente)
{
this->push_bak(val);
return 1;
}
else
if(n==0)
{
element * temp=new element;
temp->initializat=1;
temp->point_back=0;
temp->point_front=this->primul_element;
(temp->val)=val;
(this->primul_element)->point_back=temp;
this->primul_element=temp;
++(this->nr_de_elemente);
return 1;
}
else
{
element * temp=get_addres(n-1);
element * new_element= new element;
new_element->initializat=1;
new_element->val=val;
new_element->point_front=temp->point_front;
(temp->point_front)->point_back=new_element;
temp->point_front=new_element;
new_element->point_back=temp;
++(this->nr_de_elemente);
return 1;
}
}
please help
10 1424
a few errors (mainly missing <tip>) - now compiles
thanks!!! I forgot to add the parameter list when i convert it to a template :D
that was one error ( more errors but basicaly the same one) , and my compiler din't find it .
I' m using MS visual studio 2005 ( on xp pro sp 2)
i tried to compile it after i added the parameter lits but it didn't work.
I steel get:
Error 1 error LNK2019: unresolved external symbol "public: int __thiscall vector_eu<int>::erace(int,int)" (?erace@?$vector_eu@H@@QAEHHH@Z) referenced in function _wmain test vector eu.obj
Error 2 error LNK2019: unresolved external symbol "public: int __thiscall vector_eu<int>::erace(int)" (?erace@?$vector_eu@H@@QAEHH@Z) referenced in function _wmain test vector eu.obj
............. for all the functions
tis happends when i declear a function but don't write somewhere its boddy
and i use it for ex :
int max(int,int);
///// i don't write its boddy
but then i use it
c=max(a,b);
and now i surly get an error LNK2019: unresolved external symbol
so can anybody tel me wats rong in my program? din't i wrote the function's name corectly when i wrote there boddy?
i realy need this so PLS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
i realy need this so PLS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
could you post the complete code which is giving you errors? don't forget the code tags!
here is all the info
i'm using microsoft visual c++ 2005 on xp sp 2
i tested it with int tipe ( without templates ) and it worked fine
here are the header files
" stdafx.h"
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <tchar.h>
" define element.h"
#include <iostream>
using namespace std;
template <typename tip>
class element
{public:
tip val;
int initializat; /// arata daca un element e initializat sau nu
element<tip>* point_front;
element<tip>* point_back;
};
template <typename tip>
class vector_eu
{
public:
vector_eu(); //constructor
int push_bak(tip);//adauga un element in coada vectorului push_bak(element)
int insert(tip,int);//adauga un element intr-un loc specificat insert(element,pozitie)
int erace(int);//sterge un element dintr-o pozitie specificata erace(pozitie)
int erace(int,int);//sterge un nr de caractere incepand cu o pozitie specificata erace(pozitie,nr_de_elemente)
int clear(void); //sterge tot vectorul
int get(int);
private:
element<tip>* primul_element;
int nr_de_elemente;
element<tip>* ultimul_element;
element<tip>* get_addres(int);
};
" implement.cpp"
#include "stdafx.h"
#include <iostream>
#include <string>
#include "define element.h"
using namespace std;
void error(string s)
{
cout<<s<<endl;
}
template <typename tip>
inline
vector_eu<tip>::vector_eu()
{
this->nr_de_elemente=0;
this->primul_element=new element<tip>; // creaza primul element vid
this->primul_element->initializat=0;
this->primul_element->point_back=0; // pointerul spre elemntul precedent pt primul elemnt este 0
this->primul_element->point_front=0;// daca pointerul spre urmatorul element este 0 --> nu exita
this->ultimul_element=this->primul_element;
}
template <typename tip>
inline
int vector_eu<tip>::push_bak(tip val)
{
if((this->nr_de_elemente)==0)
{
(this->primul_element)->initializat=1;
(this->primul_element)->val=val;
++(this->nr_de_elemente);
return 1;
}
else
{
element<tip> * temp=new element;
temp->initializat=1;
temp->val=val;
temp->point_front=0;
temp->point_back=(this->ultimul_element);
(this->ultimul_element)->point_front=temp;
(this->ultimul_element)=temp;
++(this->nr_de_elemente);
return 1;
}
}
template <typename tip>
inline
element<tip>* vector_eu<tip>::get_addres(int n) /// iterator incepe de la 0
{
if (this->nr_de_elemente==0)
{
error("nu exista elemente");
return 0;
}
else
{ if(n<this->nr_de_elemente)
{
if(n==0) return this->primul_element;
else
{
if(n<0){ error("iterator<0");return 0;}
else
{
element<tip>*temp=this->primul_element;
while(n>0)
{
temp=temp->point_front;
--n;
}
return temp;
}
}
}
else
{
error("iterator>nr_de_elemente");
}
}
}
template <typename tip>
inline
int vector_eu<tip>::get(int n)
{
if(this->nr_de_elemente>n)
{
if(n>-1)
{
element<tip> * temp =get_addres(n);
return temp->val;
}
else {
error("iterator<0");
return 0;
}
}
else {
error("iterator>nr_de_elemente");
return 0;
}
}
template <typename tip>
inline
int vector_eu<tip>::clear(void)
{
if(this->nr_de_elemente!=0)
{
if(this->nr_de_elemente>0)
{
element<tip>* temp=this->ultimul_element;
while(this->nr_de_elemente>1)
{
temp=temp->point_back;
delete (temp->point_front);
--(this->nr_de_elemente);
}
temp->point_front=0;
temp->initializat=0;
temp->val=0;
(this->ultimul_element)=(this->primul_element);
(this->nr_de_elemente)=0;
return 1;
}
else {error("nr_de_elemente<0");return 0;}
}
else
return 1;
}
template <typename tip>
inline
int vector_eu<tip>::erace(int n)
{
if(n<this->nr_de_elemente)
{
if(n>-1)
{
if(n==0)
{
if(this->nr_de_elemente==1)
{
this->clear();
}
else
{
element<tip> *temp=this->primul_element;
this->primul_element=(this->primul_element)->point_front;
(this->primul_element)->point_back=0;
delete temp;
--(this->nr_de_elemente);
return 1;
}
}
else{
if((n+1)==this->nr_de_elemente)
{
element<tip> * temp=this->ultimul_element;
((this->ultimul_element)->point_back)->point_front=0;
(this->ultimul_element)=(this->ultimul_element)->point_back;
delete temp;
--(this->nr_de_elemente);
return 1;
}
else
{
element<tip> * temp=get_addres(n);
(temp->point_back)->point_front=temp->point_front;
(temp->point_front)->point_back=temp->point_back;
delete temp;
--(this->nr_de_elemente);
return 1;
}
}
}
else error("iterator<0");
}
else error("iterator>nr_de_elemente");
return 0;
}
template <typename tip>
inline
int vector_eu<tip>::erace(int n, int r) ///!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
{
if(n<0)
{
error("iterator poz<0");
return 0;
}
else
if(r<0)
{
error("iterator lungime<0");
return 0;
}
else
if(r==0)
{
error("iterator lungime = 0");
}
else
if((n+r)>(this->nr_de_elemente))
{
error("depaseste dimensiunea");
return 0;
}
else
{
if(r==1)
{
erace(n);
return 1;
}
else
if(n==0)
{
if(r==(this->nr_de_elemente))
{
this->clear();
return 1;
}
else
{
element<tip> * temp=(this->primul_element);
for(int i=0;i<r;++i)
{
temp=(temp->point_front);
delete (temp->point_back);
}
(this->primul_element)=temp;
(this->primul_element)->point_back=0;
this->nr_de_elemente-=r;
return 1;
}
}
else
{
if((n+r)==(this->nr_de_elemente))
{
element<tip> *temp=get_addres(n);
(this->ultimul_element)=temp->point_back;
(this->ultimul_element)->point_front=0;
for(int i=1;i<r;++i)
{
temp=temp->point_front;
delete temp->point_back;
}
delete temp;
this->nr_de_elemente-=r;
return 1;
}
else
{
element<tip> *temp=get_addres(n);
element<tip> *temp_2=(get_addres(n-1));
element<tip> *temp_3=get_addres(n+r);
temp_2->point_front=temp_3;
temp_3->point_back=temp_2;
for(int i=1;i<r;++i)
{
temp=temp->point_front;
delete temp->point_back;
}
delete temp;
this->nr_de_elemente-=r;
return 1;
}
}
}
}
template <typename tip>
inline
int vector_eu<tip>::insert(tip val, int n)
{
if((n==0)&&(this->nr_de_elemente==0))
this->push_bak(val);
else
if(n>this->nr_de_elemente)
{
error("iterator>nr_de_elemente");
return 0;
}
else
if(n<0)
{
error("iterator<0");
return 0;
}
else
if(n==this->nr_de_elemente)
{
this->push_bak(val);
return 1;
}
else
if(n==0)
{
element<tip> * temp=new element;
temp->initializat=1;
temp->point_back=0;
temp->point_front=this->primul_element;
(temp->val)=val;
(this->primul_element)->point_back=temp;
this->primul_element=temp;
++(this->nr_de_elemente);
return 1;
}
else
{
element<tip> * temp=get_addres(n-1);
element<tip> * new_element= new element;
new_element->initializat=1;
new_element->val=val;
new_element->point_front=temp->point_front;
(temp->point_front)->point_back=new_element;
temp->point_front=new_element;
new_element->point_back=temp;
++(this->nr_de_elemente);
return 1;
}
}
" test vector eu.cpp "
#include "stdafx.h"
#include "define element.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int a,b,c;
vector_eu<int> e;
while(1)
{
cout<<endl<<endl;
cout<<"1. push_bak"<<endl;
cout<<"2. insert"<<endl;
cout<<"3.clear"<<endl;
cout<<"4.get"<<endl;
cout<<"5.erace(int)"<<endl;
cout<<"6.erace(int,int)"<<endl;
cin>>a;
if(a==0) break;
switch (a)
{
case 1:
cout<<" val= ";
cin>>b;
e.push_bak(b);
break;
case 2:
cout<<"val= ";
cin>>b;
cout<<" poz= ";
cin>>c;
e.insert(b,c);
break;
case 3:
e.clear();
break;
case 4:
cout<<"poz= ";
cin>>b;
cout<<"e["<<b<<"]= "<<e.get(b);
break;
case 5:
cout<<"poz= ";
cin>>b;
e.erace(b);
break;
case 6:
cout<<"poz= ";
cin>>b;
cout<<"lungme= ";
cin>>c;
e.erace(b,c);
break;
}
}
std::system("pause");
return 0;
}
you missed a few things (indicated buy // ** comments)
I have all the code in one file so -
#include <iostream>
-
-
using namespace std;
-
-
template <typename tip>
-
class element
-
{public:
-
tip val;
-
int initializat; /// arata daca un element e initializat sau nu
-
element<tip>* point_front;
-
element<tip>* point_back;
-
-
};
-
-
-
template <typename tip>
-
class vector_eu
-
{
-
public:
-
vector_eu(); //constructor
-
int push_bak(tip);//adauga un element in coada vectorului push_bak(element)
-
int insert(tip,int);//adauga un element intr-un loc specificat insert(element,pozitie)
-
int erace(int);//sterge un element dintr-o pozitie specificata erace(pozitie)
-
int erace(int,int);//sterge un nr de caractere incepand cu o pozitie specificata erace(pozitie,nr_de_elemente)
-
int clear(void); //sterge tot vectorul
-
int get(int);
-
-
private:
-
element<tip>* primul_element;
-
int nr_de_elemente;
-
element<tip>* ultimul_element;
-
-
element<tip>* get_addres(int);
-
-
-
};
-
-
-
-
-
-
//" implement.cpp"
-
-
//#include "stdafx.h"
-
#include <iostream>
-
#include <string>
-
//#include "define element.h"
-
using namespace std;
-
-
void error(string s)
-
{
-
cout<<s<<endl;
-
}
-
-
-
template <typename tip>
-
inline
-
vector_eu<tip>::vector_eu()
-
{
-
this->nr_de_elemente=0;
-
this->primul_element=new element<tip>; // creaza primul element vid
-
this->primul_element->initializat=0;
-
this->primul_element->point_back=0; // pointerul spre elemntul precedent pt primul elemnt este 0
-
this->primul_element->point_front=0;// daca pointerul spre urmatorul element este 0 --> nu exita
-
this->ultimul_element=this->primul_element;
-
}
-
-
-
-
template <typename tip>
-
inline
-
int vector_eu<tip>::push_bak(tip val) // ** added :p
-
{
-
if((this->nr_de_elemente)==0)
-
{
-
(this->primul_element)->initializat=1;
-
(this->primul_element)->val=val;
-
++(this->nr_de_elemente);
-
return 1;
-
}
-
else
-
{
-
element<tip> * temp=new element<tip>();
-
temp->initializat=1;
-
temp->val=val;
-
temp->point_front=0;
-
temp->point_back=(this->ultimul_element);
-
(this->ultimul_element)->point_front=temp;
-
(this->ultimul_element)=temp;
-
++(this->nr_de_elemente);
-
return 1;
-
}
-
}
-
-
-
-
template <typename tip>
-
inline
-
element<tip>* vector_eu<tip>::get_addres(int n) /// iterator incepe de la 0
-
{
-
if (this->nr_de_elemente==0)
-
{
-
error("nu exista elemente");
-
return 0;
-
}
-
else
-
{ if(n<this->nr_de_elemente)
-
{
-
if(n==0) return this->primul_element;
-
else
-
{
-
if(n<0){ error("iterator<0");return 0;}
-
else
-
{
-
element<tip>*temp=this->primul_element;
-
while(n>0)
-
{
-
temp=temp->point_front;
-
--n;
-
}
-
return temp;
-
}
-
}
-
}
-
else
-
{
-
error("iterator>nr_de_elemente");
-
}
-
}
-
-
-
}
-
-
-
-
-
-
-
-
-
-
template <typename tip>
-
inline
-
int vector_eu<tip>::get(int n)
-
{
-
if(this->nr_de_elemente>n)
-
{
-
if(n>-1)
-
{
-
element<tip> * temp =get_addres(n);
-
return temp->val;
-
}
-
else {
-
error("iterator<0");
-
return 0;
-
}
-
}
-
else {
-
error("iterator>nr_de_elemente");
-
return 0;
-
}
-
}
-
-
-
-
-
template <typename tip>
-
inline
-
int vector_eu<tip>::clear(void)
-
{
-
if(this->nr_de_elemente!=0)
-
{
-
if(this->nr_de_elemente>0)
-
{
-
element<tip>* temp=this->ultimul_element;
-
while(this->nr_de_elemente>1)
-
{
-
temp=temp->point_back;
-
delete (temp->point_front);
-
--(this->nr_de_elemente);
-
}
-
temp->point_front=0;
-
temp->initializat=0;
-
temp->val=0;
-
(this->ultimul_element)=(this->primul_element);
-
(this->nr_de_elemente)=0;
-
return 1;
-
}
-
else {error("nr_de_elemente<0");return 0;}
-
}
-
else
-
return 1;
-
}
-
-
-
-
template <typename tip>
-
inline
-
int vector_eu<tip>::erace(int n)
-
{
-
if(n<this->nr_de_elemente)
-
{
-
if(n>-1)
-
{
-
if(n==0)
-
{
-
if(this->nr_de_elemente==1)
-
{
-
this->clear();
-
}
-
else
-
{
-
element<tip> *temp=this->primul_element;
-
this->primul_element=(this->primul_element)->point_front;
-
(this->primul_element)->point_back=0;
-
delete temp;
-
--(this->nr_de_elemente);
-
return 1;
-
}
-
}
-
else{
-
if((n+1)==this->nr_de_elemente)
-
{
-
element<tip> * temp=this->ultimul_element;
-
((this->ultimul_element)->point_back)->point_front=0;
-
(this->ultimul_element)=(this->ultimul_element)->point_back;
-
delete temp;
-
--(this->nr_de_elemente);
-
return 1;
-
}
-
else
-
{
-
element<tip> * temp=get_addres(n);
-
(temp->point_back)->point_front=temp->point_front;
-
(temp->point_front)->point_back=temp->point_back;
-
delete temp;
-
--(this->nr_de_elemente);
-
return 1;
-
}
-
}
-
}
-
else error("iterator<0");
-
-
}
-
else error("iterator>nr_de_elemente");
-
-
return 0;
-
}
-
-
-
-
template <typename tip>
-
inline
-
int vector_eu<tip>::erace(int n, int r) ///!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
{
-
if(n<0)
-
{
-
error("iterator poz<0");
-
return 0;
-
}
-
else
-
if(r<0)
-
{
-
error("iterator lungime<0");
-
return 0;
-
}
-
else
-
if(r==0)
-
{
-
error("iterator lungime = 0");
-
}
-
else
-
if((n+r)>(this->nr_de_elemente))
-
{
-
error("depaseste dimensiunea");
-
return 0;
-
}
-
else
-
{
-
if(r==1)
-
{
-
erace(n);
-
return 1;
-
}
-
else
-
if(n==0)
-
{
-
if(r==(this->nr_de_elemente))
-
{
-
this->clear();
-
return 1;
-
}
-
else
-
{
-
element<tip> * temp=(this->primul_element);
-
for(int i=0;i<r;++i)
-
{
-
temp=(temp->point_front);
-
delete (temp->point_back);
-
-
}
-
(this->primul_element)=temp;
-
(this->primul_element)->point_back=0;
-
this->nr_de_elemente-=r;
-
return 1;
-
}
-
}
-
else
-
{
-
if((n+r)==(this->nr_de_elemente))
-
{
-
element<tip> *temp=get_addres(n);
-
(this->ultimul_element)=temp->point_back;
-
(this->ultimul_element)->point_front=0;
-
for(int i=1;i<r;++i)
-
{
-
temp=temp->point_front;
-
delete temp->point_back;
-
}
-
delete temp;
-
this->nr_de_elemente-=r;
-
return 1;
-
}
-
else
-
{
-
element<tip> *temp=get_addres(n);
-
element<tip> *temp_2=(get_addres(n-1));
-
element<tip> *temp_3=get_addres(n+r);
-
temp_2->point_front=temp_3;
-
temp_3->point_back=temp_2;
-
for(int i=1;i<r;++i)
-
{
-
temp=temp->point_front;
-
delete temp->point_back;
-
}
-
delete temp;
-
this->nr_de_elemente-=r;
-
return 1;
-
}
-
-
}
-
}
-
}
-
-
-
template <typename tip>
-
inline
-
int vector_eu<tip>::insert(tip val, int n)
-
{
-
if((n==0)&&(this->nr_de_elemente==0))
-
this->push_bak(val);
-
else
-
if(n>this->nr_de_elemente)
-
{
-
error("iterator>nr_de_elemente");
-
return 0;
-
}
-
else
-
if(n<0)
-
{
-
error("iterator<0");
-
return 0;
-
}
-
else
-
if(n==this->nr_de_elemente)
-
{
-
this->push_bak(val);
-
-
return 1;
-
}
-
else
-
if(n==0)
-
{
-
element<tip> * temp=new element<tip>(); // ** added <tip>()
-
temp->initializat=1;
-
temp->point_back=0;
-
temp->point_front=this->primul_element;
-
(temp->val)=val;
-
(this->primul_element)->point_back=temp;
-
this->primul_element=temp;
-
++(this->nr_de_elemente);
-
return 1;
-
}
-
else
-
{
-
element<tip> * temp=get_addres(n-1);
-
element<tip> * new_element= new element<tip>(); // ** added <tip>()
-
-
new_element->initializat=1;
-
new_element->val=val;
-
-
new_element->point_front=temp->point_front;
-
(temp->point_front)->point_back=new_element;
-
temp->point_front=new_element;
-
new_element->point_back=temp;
-
++(this->nr_de_elemente);
-
return 1;
-
-
}
-
-
}
-
-
-
-
-
//" test vector eu.cpp "
-
-
//#include "stdafx.h"
-
//#include "define element.h"
-
//#include <iostream>
-
-
//using namespace std;
-
-
int main(int argc, char* argv[]) // ** change to normal main()
-
{
-
int a,b,c;
-
-
vector_eu<int> e;
-
while(1)
-
{
-
-
cout<<endl<<endl;
-
cout<<"1. push_bak"<<endl;
-
cout<<"2. insert"<<endl;
-
cout<<"3.clear"<<endl;
-
cout<<"4.get"<<endl;
-
cout<<"5.erace(int)"<<endl;
-
cout<<"6.erace(int,int)"<<endl;
-
cin>>a;
-
if(a==0) break;
-
switch (a)
-
{
-
case 1:
-
cout<<" val= ";
-
cin>>b;
-
-
e.push_bak(b);
-
break;
-
case 2:
-
cout<<"val= ";
-
cin>>b;
-
cout<<" poz= ";
-
cin>>c;
-
e.insert(b,c);
-
break;
-
case 3:
-
e.clear();
-
break;
-
case 4:
-
cout<<"poz= ";
-
cin>>b;
-
cout<<"e["<<b<<"]= "<<e.get(b);
-
break;
-
case 5:
-
cout<<"poz= ";
-
cin>>b;
-
e.erace(b);
-
break;
-
case 6:
-
cout<<"poz= ";
-
cin>>b;
-
cout<<"lungme= ";
-
cin>>c;
-
e.erace(b,c);
-
break;
-
-
}
-
-
}
-
-
std::system("pause");
-
return 0;
-
}
-
I compile it with gcc and when run it gives
1. push_bak
2. insert
3.clear
4.get
5.erace(int)
6.erace(int,int)
1
val= 45
1. push_bak
2. insert
3.clear
4.get
5.erace(int)
6.erace(int,int)
1
val= 23
1. push_bak
2. insert
3.clear
4.get
5.erace(int)
6.erace(int,int)
4
poz= 1
e[1]= 23
1. push_bak
2. insert
3.clear
4.get
5.erace(int)
6.erace(int,int)
i modifaide it but stil doesn't work
i stil get :
Error 1 error LNK2019: unresolved external symbol "public: int __thiscall vector_eu<int>::erace(int,int)" (?erace@?$vector_eu@H@@QAEHHH@Z) referenced in function _wmain test vector eu.obj
one for each function
does any on know why?
the code in my last post works OK with DEV-C++ & Borland V5.6 under windows and gnu C++ under Linux
tried the code with VC V5.0 had to make a cople of modifiactions (marked in code below) and it ran OK
copy this and save it into a single file - it should compile and run -
#include <iostream>
-
-
using namespace std;
-
-
template <typename tip>
-
class element
-
{public:
-
tip val;
-
int initializat; /// arata daca un element e initializat sau nu
-
element<tip>* point_front;
-
element<tip>* point_back;
-
-
};
-
-
-
template <typename tip>
-
class vector_eu
-
{
-
public:
-
vector_eu(); //constructor
-
int push_bak(tip);//adauga un element in coada vectorului push_bak(element)
-
int insert(tip,int);//adauga un element intr-un loc specificat insert(element,pozitie)
-
int erace(int);//sterge un element dintr-o pozitie specificata erace(pozitie)
-
int erace(int,int);//sterge un nr de caractere incepand cu o pozitie specificata erace(pozitie,nr_de_elemente)
-
int clear(void); //sterge tot vectorul
-
int get(int);
-
-
private:
-
element<tip>* primul_element;
-
int nr_de_elemente;
-
element<tip>* ultimul_element;
-
-
element<tip>* get_addres(int);
-
-
-
};
-
-
-
//" implement.cpp"
-
-
//#include "stdafx.h"
-
#include <iostream>
-
#include <string>
-
//#include "define element.h"
-
using namespace std;
-
-
void error(string s)
-
{
-
cout<<s<<endl;
-
}
-
-
-
template <typename tip>
-
inline
-
vector_eu<tip>::vector_eu()
-
{
-
this->nr_de_elemente=0;
-
this->primul_element=new element<tip>; // creaza primul element vid
-
this->primul_element->initializat=0;
-
this->primul_element->point_back=0; // pointerul spre elemntul precedent pt primul elemnt este 0
-
this->primul_element->point_front=0;// daca pointerul spre urmatorul element este 0 --> nu exita
-
this->ultimul_element=this->primul_element;
-
}
-
-
-
-
template <typename tip>
-
inline
-
int vector_eu<tip>::push_bak(tip val) // ** added :p
-
{
-
if((this->nr_de_elemente)==0)
-
{
-
(this->primul_element)->initializat=1;
-
(this->primul_element)->val=val;
-
++(this->nr_de_elemente);
-
return 1;
-
}
-
else
-
{
-
element<tip> * temp=new element<tip>();
-
temp->initializat=1;
-
temp->val=val;
-
temp->point_front=0;
-
temp->point_back=(this->ultimul_element);
-
(this->ultimul_element)->point_front=temp;
-
(this->ultimul_element)=temp;
-
++(this->nr_de_elemente);
-
return 1;
-
}
-
}
-
-
-
-
template <typename tip>
-
inline
-
element<tip>* vector_eu<tip>::get_addres(int n) /// iterator incepe de la 0
-
{
-
if (this->nr_de_elemente==0)
-
{
-
error("nu exista elemente");
-
return 0;
-
}
-
else
-
{ if(n<this->nr_de_elemente)
-
{
-
if(n==0) return this->primul_element;
-
else
-
{
-
if(n<0){ error("iterator<0");return 0;}
-
else
-
{
-
element<tip>*temp=this->primul_element;
-
while(n>0)
-
{
-
temp=temp->point_front;
-
--n;
-
}
-
return temp;
-
}
-
}
-
}
-
else
-
{
-
error("iterator>nr_de_elemente");
-
}
-
}
-
return 0; // ** added for VC
-
-
}
-
-
-
-
template <typename tip>
-
inline
-
int vector_eu<tip>::get(int n)
-
{
-
if(this->nr_de_elemente>n)
-
{
-
if(n>-1)
-
{
-
element<tip> * temp =get_addres(n);
-
return temp->val;
-
}
-
else {
-
error("iterator<0");
-
return 0;
-
}
-
}
-
else {
-
error("iterator>nr_de_elemente");
-
return 0;
-
}
-
}
-
-
-
template <typename tip>
-
inline
-
int vector_eu<tip>::clear(void)
-
{
-
if(this->nr_de_elemente!=0)
-
{
-
if(this->nr_de_elemente>0)
-
{
-
element<tip>* temp=this->ultimul_element;
-
while(this->nr_de_elemente>1)
-
{
-
temp=temp->point_back;
-
delete (temp->point_front);
-
--(this->nr_de_elemente);
-
}
-
temp->point_front=0;
-
temp->initializat=0;
-
temp->val=0;
-
(this->ultimul_element)=(this->primul_element);
-
(this->nr_de_elemente)=0;
-
return 1;
-
}
-
else {error("nr_de_elemente<0");return 0;}
-
}
-
else
-
return 1;
-
}
-
-
-
-
template <typename tip>
-
inline
-
int vector_eu<tip>::erace(int n)
-
{
-
if(n<this->nr_de_elemente)
-
{
-
if(n>-1)
-
{
-
if(n==0)
-
{
-
if(this->nr_de_elemente==1)
-
{
-
this->clear();
-
}
-
else
-
{
-
element<tip> *temp=this->primul_element;
-
this->primul_element=(this->primul_element)->point_front;
-
(this->primul_element)->point_back=0;
-
delete temp;
-
--(this->nr_de_elemente);
-
return 1;
-
}
-
}
-
else{
-
if((n+1)==this->nr_de_elemente)
-
{
-
element<tip> * temp=this->ultimul_element;
-
((this->ultimul_element)->point_back)->point_front=0;
-
(this->ultimul_element)=(this->ultimul_element)->point_back;
-
delete temp;
-
--(this->nr_de_elemente);
-
return 1;
-
}
-
else
-
{
-
element<tip> * temp=get_addres(n);
-
(temp->point_back)->point_front=temp->point_front;
-
(temp->point_front)->point_back=temp->point_back;
-
delete temp;
-
--(this->nr_de_elemente);
-
return 1;
-
}
-
}
-
}
-
else error("iterator<0");
-
-
}
-
else error("iterator>nr_de_elemente");
-
-
return 0;
-
}
-
-
-
-
template <typename tip>
-
inline
-
int vector_eu<tip>::erace(int n, int r) ///!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
{
-
if(n<0)
-
{
-
error("iterator poz<0");
-
return 0;
-
}
-
else
-
if(r<0)
-
{
-
error("iterator lungime<0");
-
return 0;
-
}
-
else
-
if(r==0)
-
{
-
error("iterator lungime = 0");
-
}
-
else
-
if((n+r)>(this->nr_de_elemente))
-
{
-
error("depaseste dimensiunea");
-
return 0;
-
}
-
else
-
{
-
if(r==1)
-
{
-
erace(n);
-
return 1;
-
}
-
else
-
if(n==0)
-
{
-
if(r==(this->nr_de_elemente))
-
{
-
this->clear();
-
return 1;
-
}
-
else
-
{
-
element<tip> * temp=(this->primul_element);
-
for(int i=0;i<r;++i)
-
{
-
temp=(temp->point_front);
-
delete (temp->point_back);
-
-
}
-
(this->primul_element)=temp;
-
(this->primul_element)->point_back=0;
-
this->nr_de_elemente-=r;
-
return 1;
-
}
-
}
-
else
-
{
-
if((n+r)==(this->nr_de_elemente))
-
{
-
element<tip> *temp=get_addres(n);
-
(this->ultimul_element)=temp->point_back;
-
(this->ultimul_element)->point_front=0;
-
for(int i=1;i<r;++i)
-
{
-
temp=temp->point_front;
-
delete temp->point_back;
-
}
-
delete temp;
-
this->nr_de_elemente-=r;
-
return 1;
-
}
-
else
-
{
-
element<tip> *temp=get_addres(n);
-
element<tip> *temp_2=(get_addres(n-1));
-
element<tip> *temp_3=get_addres(n+r);
-
temp_2->point_front=temp_3;
-
temp_3->point_back=temp_2;
-
for(int i=1;i<r;++i)
-
{
-
temp=temp->point_front;
-
delete temp->point_back;
-
}
-
delete temp;
-
this->nr_de_elemente-=r;
-
return 1;
-
}
-
-
}
-
}
-
return 0; // ** added for VC
-
}
-
-
-
template <typename tip>
-
inline
-
int vector_eu<tip>::insert(tip val, int n)
-
{
-
if((n==0)&&(this->nr_de_elemente==0))
-
this->push_bak(val);
-
else
-
if(n>this->nr_de_elemente)
-
{
-
error("iterator>nr_de_elemente");
-
return 0;
-
}
-
else
-
if(n<0)
-
{
-
error("iterator<0");
-
return 0;
-
}
-
else
-
if(n==this->nr_de_elemente)
-
{
-
this->push_bak(val);
-
-
return 1;
-
}
-
else
-
if(n==0)
-
{
-
element<tip> * temp=new element<tip>(); // ** added <tip>()
-
temp->initializat=1;
-
temp->point_back=0;
-
temp->point_front=this->primul_element;
-
(temp->val)=val;
-
(this->primul_element)->point_back=temp;
-
this->primul_element=temp;
-
++(this->nr_de_elemente);
-
return 1;
-
}
-
else
-
{
-
element<tip> * temp=get_addres(n-1);
-
element<tip> * new_element= new element<tip>(); // ** added <tip>()
-
-
new_element->initializat=1;
-
new_element->val=val;
-
-
new_element->point_front=temp->point_front;
-
(temp->point_front)->point_back=new_element;
-
temp->point_front=new_element;
-
new_element->point_back=temp;
-
++(this->nr_de_elemente);
-
return 1;
-
-
}
-
-
return 0; // ** added for VC
-
}
-
-
-
-
-
//" test vector eu.cpp "
-
-
//#include "stdafx.h"
-
//#include "define element.h"
-
//#include <iostream>
-
-
//using namespace std;
-
-
int main(int argc, char* argv[]) // ** change to normal main()
-
{
-
int a,b,c;
-
-
vector_eu<int> e;
-
while(1)
-
{
-
-
cout<<endl<<endl;
-
cout<<"1. push_bak"<<endl;
-
cout<<"2. insert"<<endl;
-
cout<<"3.clear"<<endl;
-
cout<<"4.get"<<endl;
-
cout<<"5.erace(int)"<<endl;
-
cout<<"6.erace(int,int)"<<endl;
-
cin>>a;
-
if(a==0) break;
-
switch (a)
-
{
-
case 1:
-
cout<<" val= ";
-
cin>>b;
-
-
e.push_bak(b);
-
break;
-
case 2:
-
cout<<"val= ";
-
cin>>b;
-
cout<<" poz= ";
-
cin>>c;
-
e.insert(b,c);
-
break;
-
case 3:
-
e.clear();
-
break;
-
case 4:
-
cout<<"poz= ";
-
cin>>b;
-
cout<<"e["<<b<<"]= "<<e.get(b);
-
break;
-
case 5:
-
cout<<"poz= ";
-
cin>>b;
-
e.erace(b);
-
break;
-
case 6:
-
cout<<"poz= ";
-
cin>>b;
-
cout<<"lungme= ";
-
cin>>c;
-
e.erace(b,c);
-
break;
-
-
}
-
-
}
-
-
system("pause"); // ** remove std:: for VC
-
return 0;
-
}
-
Thanks I Tried It . And It Works !!!
By The Way Happy New Year!!!!!!!!!!
But I Wat To Have The Code In Different Files Like A Header File And A Code File So I Can Include The Header In Different Other Files Without Copying The Code.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Vince C. |
last post by:
Hi all,
I've created XML documents that are described with a schema. I'm using those
documents to create web pages.
All my web pages contain a fixed header and a variable document part. The...
|
by: Tom Alsberg |
last post by:
Hi there...
I'm recently trying to get a bit acquainted with XML Schemas and XSL.
Now, I have a few questions about XSL stylesheets and templates:
* Is there a way to "enter" a child element...
|
by: E. Robert Tisdale |
last post by:
According to the C++ FAQ Lite:
http://www.parashift.com/
What is "genericity"?
Yet another way to say, "class templates."
Not to be confused with "generality"
(which just means avoiding...
|
by: Fabio De Francesco |
last post by:
Hello.
I can't understand why I can't compile the following simple code, where
I think I have applied all the needed rules for templates that are
declared and defined in different files (*.h and...
|
by: WittyGuy |
last post by:
Hi,
What is the major difference between function overloading and function
templates?
Thanks!
http://www.gotw.ca/resources/clcm.htm for info about ]
|
by: jimbo_vr5 |
last post by:
Hey
I think i've figured out the idea behind apply-templates. But going
through the tutorial on
<http://www.w3schools.com/xsl/xsl_apply_templates.asp> theres simply
just something that i dont...
|
by: Ted |
last post by:
I'm putting the posts that follow here (hopefully they will follow here!) because
they were rejected in comp.lang.c++.moderated. It behooves anyone reading
them to first read the the thread of the...
|
by: NewToCPP |
last post by:
Hi,
I am just trying to find out if there is any strong reason for not
using Templates. When we use Templates it is going to replicate the
code for different data types, thus increasing the...
|
by: JohnQ |
last post by:
Well apparently not since one can step thru template code with a debugger.
But if I was willing to make the concession on debugging, templates would be
strictly a precompiler thing? I have a...
|
by: Chris |
last post by:
Hi All,
This is a weird one but I am hoping someone can help or has some
pointers, a recipe how to do the following:
I have to move some code from c++ to objective-c and to do this I must...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |