TuxedoTemplar
Programmer
I've gone over this thing with a fine-tooth comb until my face is blue and I've only narrowed it down to the delete[] operators in the destructor not working (the program gives an assertion error.) As far as I've learned and I can observe everything is done as it should be, so I'm basically clueless now. I'm no good at explaining things, so I'll just post the abreviated code samples:
PageSection Class Header
PageSection Constructor and Destructor
Test Program
Any help would be GREATLY appreciated!
PageSection Class Header
Code:
#ifndef PAGESECTION
#define PAGESECTION
class PageSection
{
public:
PageSection(const char *label, const char *body, const char *timestamp, int subsections = 0);
~PageSection();
char *getLabel();
char *getBody();
char *getTimestamp();
int getSubsectionNum();
void setLabel(const char *label);
void setBody(const char *body);
void setTimestamp(const char *timestamp);
void setSubsectionNum(const int num);
private:
char *LABEL;
char *BODY;
char *TIMESTAMP;
int LABELSIZE;
int BODYSIZE;
int TIMESTAMPSIZE;
int SUBSECTIONS;
};
#endif
PageSection Constructor and Destructor
Code:
#include <cstring>
#include "PageSection.h"
PageSection::PageSection(const char *label, const char *body, const char *timestamp, int subsections)
{
LABEL = NULL;
LABELSIZE = 0;
BODY = NULL;
BODYSIZE = 0;
TIMESTAMP = NULL;
TIMESTAMPSIZE = 0;
SUBSECTIONS = subsections;
if(label)
{
LABELSIZE = strlen(label + 1);
LABEL = new char[LABELSIZE];
strcpy(LABEL, label);
}
if(body)
{
BODYSIZE = strlen(body + 1);
BODY = new char[BODYSIZE];
strcpy(BODY, body);
}
if(timestamp)
{
TIMESTAMPSIZE = strlen(timestamp + 1);
TIMESTAMP = new char[TIMESTAMPSIZE];
strcpy(TIMESTAMP, timestamp);
}
}
PageSection::~PageSection()
{
if(LABELSIZE)
delete[] LABEL;
if(BODYSIZE)
delete[] BODY;
if(TIMESTAMPSIZE)
delete[] TIMESTAMP;
}
...
Test Program
Code:
#include <iostream>
#include "PageSection.h"
#include "Page.h"
using std::cout;
using std::cin;
using std::endl;
void main()
{
PageSection Hoy("Hi", "Ho", "Yo", 0);
cout << Hoy.getLabel() << endl << Hoy.getBody()
<< Hoy.getTimestamp() << endl;
return;
}
Any help would be GREATLY appreciated!