Im having problems with class data and linked list, after the constructor is called with the textfile parameter head points to null. after attempting to debug it none of the destructors were called so i am lost in where its deleting the objects from the linked list.
code in main
char fileName[] = "data.txt";
queue housesOnList(fileName);
data house;
stack houseInterested;
char response;
cout << "\nthe houses we will visit today:" << endl << endl;
housesOnList.display ();
class functions
queue::queue(const char * textfile)
{
data house;
queue houses;
char * sqFoot = new char[1];
char * bedR = new char[1];
char * bathR = new char[1];
string addr;
string description;
ifstream myfile(textfile);
if (myfile.is_open())
{
while (!myfile.eof())
{
getline(myfile, addr);
getline(myfile, description);
myfile >> sqFoot >> bedR >> bathR;
house.setAddress(addr.c_str());
house.setDiscription(description.c_str());
house.setSqFoot(atoi(sqFoot));
house.setBedrooms(atoi(bedR));
house.setBathroom(atof(bathR));
houses.enqueue(house);
}
}
}
void queue::enqueue(data & item)
{
Node * n = new Node(item);
/*if (head != NULL)
{
n->next = head;
head = n;
return;
}
else
{
head = n;
return;
}*/
n->next = NULL;
if (head != NULL)
{
curr = head;
while (curr->next != NULL)
{
curr = curr->next;
}
curr->next = n;
}
else
{
head = n;
}
}
object class
data::data()
{
this->Address = NULL;
this->Description = NULL;
Bedr = 0;
Bathr = 0;
sqFoot = 0;
}
data::data(const data & item)
{
*this = item;
}
/*data::~data()
{
if (this->Address)
{
delete[] this->Address;
}
}*/
const char* data::getAddress()
{
return this->Address;
}
const char *data::getDescription()
{
return this->Description;
}
int data::getBedrooms() const
{
return Bedr;
}
int data::getSqFoot() const
{
return sqFoot;
}
float data::getBathroom() const
{
return Bathr;
}
void data::setAddress(const char * addr)
{
if (this->Address)
{
delete[] this->Address;
}
this->Address = new char[strlen(addr) + 1];
strcpy(this->Address, addr);
}
void data::setDiscription(const char * desc)
{
if (this->Description)
{
delete[] this->Description;
}
this->Description = new char[strlen(desc) + 1];
strcpy(this->Description, desc);
}
bool data::setBathroom(const float bathR)
{
if (bathR < MIN)
{
return false;
}
this->Bathr = bathR;
return true;
}
bool data::setBedrooms(const int bedR)
{
if (bedR < MIN)
{
return false;
}
this->Bedr = bedR;
return true;
}
bool data::setSqFoot(const int sqFoot)
{
if (sqFoot < MIN)
{
return false;
}
this->sqFoot = sqFoot;
return true;
}
ostream& operator<< (ostream& out, const data& house)
{
out << house.Address << "\t" << house.Description << "\t" << house.sqFoot << "\t" << house.Bedr << "\t" << house.Bathr << "\t" << endl;
//item.print();
return out;
}
void data::operator= (const data& s)
{
if (this == &s)
return;
this->sqFoot = s.sqFoot;
//this->id = s.id;
setAddress(s.Address);
setDiscription(s.Description);
this->Bedr = s.Bedr;
this->Bathr = s.Bathr;
}
Thanks in advanced !