1. Main problem is that you also need to define operator=.
2. you can simplify other parts. '
3. You need better formatting style. to make the code easier to read.
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std ;
class twodimfield
{
public:
size_t sizeP;
string itsmali;
int itsline, itsrow, itsFragment, nslova;
char **polje;
twodimfield(int nslova, string mali);
twodimfield(const twodimfield &L);
void operator=(const twodimfield& t);
~twodimfield();
};
twodimfield::twodimfield(int nslova, string mali)
{
int i;
itsrow = nslova+1;
itsmali = mali;
sizeP = itsmali.size();
itsline = sizeP;
itsFragment = sizeP-(nslova-1);
polje = new char * [itsline];
for(i=0; i<itsline; i++)
{
polje[i] = new char[itsrow];
memset(polje[i],0,itsrow);
}
for (i=0; i < itsFragment; i++)
{
string s2;
for (int j=0; j<nslova; j++)
{
s2 += mali[i+j];
}
for (int l=0; l<itsrow; l++)
{
polje[i][l] = s2[l];
}
}
}
twodimfield::twodimfield(const twodimfield &L)
{
operator=(L);
}
void twodimfield::operator=(const twodimfield &L)
{
itsline = L.itsline;
itsrow = L.itsrow;
polje = new char * [itsline];
for(int i=0; i<itsline; i++)
{
polje[i] = new char[itsrow];
memcpy(polje[i],L.polje[i],itsrow);
}
cout<<"copy constructor"<<endl;
}
twodimfield::~twodimfield()
{
for (int i=0; i<itsline; i++)
{
delete [] polje[i];
}
delete [] polje;
cout<<"destructor"<<endl;
}
int main()
{
int nslova=4;
string neki("mariomario");
twodimfield objekt2(5,neki);
twodimfield objekt(4,neki);
objekt2 = objekt;
cout<<objekt.polje[1][1]<<endl;
system("PAUSE");
return 0;
} Ancient Dragon
Retired & Loving It
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343