Hello everyone,
I am having trouble with a part of my Assignment and think i am missing something here. I have a Field class as below:
class Field{
char * fstr;
int frow, fcol, len, fslen, foffset, fstart, fctype;
bool fedt;
static int finsert;
public:
Field(char * str, int row, int col, int flen, int slen, int offset=0, int start=0, int ctype=1);
void draw( ) const;
int draw(int row, int col, int l, int h, char edge, char top_btm, char ls_rs) const;
bool editable( ) const;
int edit();
char * data( );
friend int console_Edit(char *, int, int, int, int, int *, int *, int *, int);
};
And the definition of the constructor is:
Field::Field(char * str, int row, int col, int flen, int slen, int offset, int start, int ctype){
fstr = new char[slen];
strcpy(fstr, str);
frow = row;
fcol = col;
len = flen;
fslen = slen;
foffset = offset;
fstart = start;
fctype = ctype;
}
Now I use these Field objects in a class called TextField:
class TextField{
Field * lines;
int txtWidth, txtHeight, txtRow, txtCol;
char txtEdge, txtTop_btm, txtLs_rs;
char * txtPage;
public:
TextField(char *page, int row, int col, int width, int height, char edge, char top_btm, char ls_rs);
int edit();
~TextField();
};
with the constructor as:
TextField::TextField(char *page, int row, int col, int width, int height, char edge='+', char top_btm='-', char ls_rs='|'){
txtPage = new char[strlen(page)];
strcpy(txtPage, page);
int num = strlen(page) / width;
lines = new Field [num];
int done = 0;
char * temp = new char[width];;
for(int i = 0; i < num; i++){
temp = getLine(txtPage, width - 2, i, done);
lines[i] = new Field(temp, row + i, col, width, width, 0, 0, 0);
done = strlen(temp);
}
txtRow = row;
txtCol = col;
txtWidth = width;
txtHeight = height;
txtEdge = edge;
txtTop_btm = top_btm;
txtLs_rs = ls_rs;
}
The problem is that I dnt have a constructor for Field that accepts 0 arguments. So I created a blank constructor. Also, When in the TextField's constructor, when the value for 'i' in the for loop goes above 1, I get a memory allocation error.
Can someone please help me?? I already have 600 lines of code that is working fine when tested individually, but the constructor is screwing everything up!