[prog] This segmetation fault makes no sence to me.
Sue Stones
suzo at bigpond.net.au
Fri May 30 20:27:58 EST 2003
Well I soved my loader error eventually, but now I have a segnemtation fault
and I have no idea what it might be causing it. I think of segmentation
faults as trying to access some address that the program has no rights to.
But in this case the fault occurs when it has fininished doing anything. I
will copy the relevent functions below with the output.
As far as I understand it is not until after smith has been added and
everything initialised, and when things are falling back out of the end of
functions that the segementation fault occurs.
Can anyone shed any light on this?
sue
$ firm
Constructing Employee
conctructing Manager
Constructing Employee
seting salary
anual salary is 350000
_head is empty 0xbffff814
_head is assigned e 0xbffff814
Segmentation fault
int main(void)
{
Firm andCo = Firm();
Manager smith = Manager("Smith", 1, 350000);
andCo.add(smith);
return 0;
}//main
Manager::Manager(char *e_name, int e_num, int annual_salary)
{
cout << "conctructing Manager\n";
Employee(e_name, e_num);
setSalary(annual_salary);
}//constructor
Employee::Employee(char *e_name, int e_num)
{
cout << " Constructing Employee\n";
setName(e_name);
setNumber(e_num);
_next = 0; // null pointer
}//constructor
void Firm::add(Employee e)
{
if (isEmpty())
{
cout << "_head is empty " << &e << "\n";
_head = &e;
cout << "_head is assigned e " << &e << "\n";
}
else
{ }//else
}// add a Employee to the list
void Manager::setSalary(int anual_salary)
{
cout << "seting salary\n";
_salary = anual_salary;
cout << "anual salary is " << _salary << "\n";
}// setSalary
More information about the Programming
mailing list