operator= ...what's wrong?
Hello! i want to define operator=...and i don't know what is wrong! just look:
.h
1 2 3 4 5 6 7 8 9 10 11
|
class Tablica
{
private:
int *bufor;
int rozmiar;
public:
Tablica(int rozmiar);
~Tablica();
int PobierzRozmiar() const {return rozmiar;}
Tablica &operator=(const Tablica&);
};
|
and .cpp
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
|
using namespace std;
Tablica::Tablica(int rozmiar)
{
if (rozmiar<0) /*throw F()*/;
if (rozmiar==0) /*throw E()*/;
if (rozmiar<10) /*throw D()*/;
if (rozmiar>1000) /*throw C()*/;
bufor=new int[rozmiar];
}
Tablica::~Tablica()
{
delete []bufor;
}
Tablica& Tablica::operator=(const Tablica &tablica)
{
if(this==&tablica) return *this;
rozmiar=tablica.PobierzRozmiar();
delete [] bufor;
bufor=new int[rozmiar];
for (int i=0; i<rozmiar; i++)
{
bufor[i]=tablica[i];
}
return *this;
}
|
no match for 'operator[]' in 'tablica[i]' <----that's the error... i don't know why?! can you tell me??
Line 26: bufor[i]=tablica.bufor[i];
thank you!:)
Topic archived. No new replies allowed.