Here's the function, when called, causes the core dump:
Code:
bool StoreList::add(Store h)
{
cout << "in here" <<endl;
Store temp;
temp.name="void";
int z=0, b;
b=listsize;
if(list[l-1].name == temp.name)
{
while(list[z].name<h.name)
{
z++;
}
for(int i=0; i<(l-z); i++)
{
list[b+1]=list[b];
b--;
}
list[z]=h;
return true;
}
else
{
cout << "list is full" <<endl;
return false;
}
}
Heres the code in main.cc calling it, i cut it off where it doesn't get past:
Code:
Store store1;
string storeName;
StoreList List;
int number;
cout << "******************************** FIRST TEST" << endl;
cin >> number;
for (int i = 0; i < number; i++) {
store1.read(cin);
cout << "ran the read" <<endl;
List.add(store1);
Heres my copy constructor in Store:
Code:
Store::Store(const Store &d)
{
copy(d);
}
void Store::copy(const Store &d)
{
int i;
name=d.name;
revenue=d.revenue;
numOwners=d.numOwners;
for(i=0; i < numOwners; i++)
{
owners[i]=d.owners[i];
}
}
And lastly, my class definitions:
Code:
#ifndef STORE_H
#define STORE_H
#include <iostream>
#include <string>
#include "Owner.h"
using namespace std;
class Store
{
public:
Store(string nameIn = "NONAME", float revenueIn = 0.0,
int numOwnersIn = 0, Owner *ownersIn = NULL);
Store(const Store &s);
Store& operator=(const Store &s);
~Store();
string getName();
float getRevenue();
void ownerInfo(int &numOwnersOut, Owner *&ownersOut);
void read(istream &input);
void print(ostream &output);
string name;
private:
float revenue;
int numOwners;
Owner *owners;
void copy(const Store &s);
void free();
};
#endif
#ifndef STORELIST_H
#define STORELIST_H
#include <iostream>
#include "Store.h"
#include "Owner.h"
#include <string>
using namespace std;
class StoreList
{
public:
StoreList();
StoreList(const StoreList &w);
StoreList& operator=(const StoreList &w);
~StoreList();
bool full();
bool empty();
bool add(Store h);
bool remove(string p);
void removeAll();
int size();
void print(ostream &out);
void reset();
void goNext();
bool atEnd();
void getCurrent(Store &p);
void setCurrent(Store &p);
private:
static const int maxsize=80;
int l;
Store list[maxsize];
int listsize;
Store *curr;
int d;
};
#endif
If I change the add fct to pass by reference, thats when I get the error msg I listed in the first post....as it is written here it compiles,and dumps
Lets hope i did those code tags right
Arm