Magog
Početnik
- Poruka
- 36
Molim Vas za hitno objasnjenje!!!!!
Kad ovaj kod napisem bez template-a sve funkcionise OK, ali kad ubacim template, greske se javljaju. Naime, dok u main f-ji ne napisem vektor=i sve funkcionira. Kad to napisem prilkom linkovanja mi prijavi dole navedenu gresku. Isto se desava ako probam sa pozivanjem f-je print sa vektor.print(); Verovatno je neki problem usled neadekvatnog oznacavanja template i pozivanja f-ja s njima ali ja vec duze vreme ne mogu da skapiram u cemu gresim problem. Molim Vas, ako neko moze da pojasni ovo i da izgubi malo vremena, bio bih veoma zahvalan !!! H V A L A U N A P R E D !!!!
template <class T>
class Array {
protected:
T *data;
long base;
unsigned long length;
public:
Array(long m, long l) {
length=l;
data=new T[l];
base=m;
}
Array(long l) {length=l; data=new int[l]; base=0; }
~Array() {delete [] data;}
void print ();
operator= (Array<T>& array);
T& operator[](long index);
};
*************************************************************
template <class T>
void Array<T>:
rint() {
if (length>10) throw new SBPException("*** Index out of bound!");
for(unsigned long i=0; i<length; i++)
cout<<"data["<<i<<"]="<<data<<endl;
}
template <class T>
Array<T>:
perator= (Array<T>& array) {
if (&array != this) {
if (length !=array.getLength()) {
length= array.getLength();
data=new T[length];
}
for (unsigned long i=0; i<length; i++)
data=array.data;
base=array.getBase();
}
}
template <class T>
T& Array<T>:
perator [](long index) {
unsigned long offset=index-base;
if (offset>=length)
throw new SBPException("*** Index out of bound!");
return data[offset];
}
***********************************************
#include <iostream.h>
#include "polja.h"
void main() {
Array<int> vektor(10); int dim;
cout<<"Unesi dimenziju: "; cin>>dim;
for (int i=0; i<dim; i++) vektor=i;
}
--------------------Configuration: polja - Win32 Debug--------------------
Compiling...
poljaiz.cpp
Linking...
poljaiz.obj : error LNK2001: unresolved external symbol "public: int & __thiscall Array<int>:
perator[](long)" (??A?$Array@H@@QAEAAHJ@Z)
Debug/polja.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
polja.exe - 2 error(s), 0 warning(s)
Kad ovaj kod napisem bez template-a sve funkcionise OK, ali kad ubacim template, greske se javljaju. Naime, dok u main f-ji ne napisem vektor=i sve funkcionira. Kad to napisem prilkom linkovanja mi prijavi dole navedenu gresku. Isto se desava ako probam sa pozivanjem f-je print sa vektor.print(); Verovatno je neki problem usled neadekvatnog oznacavanja template i pozivanja f-ja s njima ali ja vec duze vreme ne mogu da skapiram u cemu gresim problem. Molim Vas, ako neko moze da pojasni ovo i da izgubi malo vremena, bio bih veoma zahvalan !!! H V A L A U N A P R E D !!!!
template <class T>
class Array {
protected:
T *data;
long base;
unsigned long length;
public:
Array(long m, long l) {
length=l;
data=new T[l];
base=m;
}
Array(long l) {length=l; data=new int[l]; base=0; }
~Array() {delete [] data;}
void print ();
operator= (Array<T>& array);
T& operator[](long index);
};
*************************************************************
template <class T>
void Array<T>:

if (length>10) throw new SBPException("*** Index out of bound!");
for(unsigned long i=0; i<length; i++)
cout<<"data["<<i<<"]="<<data<<endl;
}
template <class T>
Array<T>:

if (&array != this) {
if (length !=array.getLength()) {
length= array.getLength();
data=new T[length];
}
for (unsigned long i=0; i<length; i++)
data=array.data;
base=array.getBase();
}
}
template <class T>
T& Array<T>:

unsigned long offset=index-base;
if (offset>=length)
throw new SBPException("*** Index out of bound!");
return data[offset];
}
***********************************************
#include <iostream.h>
#include "polja.h"
void main() {
Array<int> vektor(10); int dim;
cout<<"Unesi dimenziju: "; cin>>dim;
for (int i=0; i<dim; i++) vektor=i;
}
--------------------Configuration: polja - Win32 Debug--------------------
Compiling...
poljaiz.cpp
Linking...
poljaiz.obj : error LNK2001: unresolved external symbol "public: int & __thiscall Array<int>:

Debug/polja.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
polja.exe - 2 error(s), 0 warning(s)