null pointer inheritance


class employee1
{
employee1(
string _id="0",
string _name="0",
string _date="0",
string _phone="0",
string _email="0",
bool _sent=0,
string _notes="0"
):id(_id),name(_name),date(_date),phone(_phone),email(_email),sent(_sent),
notes(_notes){}

employee1(const employee1& copy)
{

name=date=phone=email=notes="0";
sent=0;
*this=copy;

}
};
class employee2:public employee1
{


employee2(employee1& copy=employee1(),
string _responsedate="0",string _application="0",string _resume="0",bool _callback=0,string _notes=0)
:responsedate(_responsedate),application(_application),resume(_resume),
callback(_callback)
{
(employee1&)*this=copy;
addnotes(_notes);
}

employee2(const employee2& copy)
{
responsedate=
application=
resume="0";
callback=0;

*this=copy;

}

}
void main()
{
employee1 e1; //ok
employee2 e2; //run time null pointer error
[code] "Please use code tags" [/code]
1
2
3
4
5
6
employee1(const employee1& copy)
{
  name=date=phone=email=notes="0";
  sent=0;
  *this=copy; //¿what do you think this line does?
}


Also main must return int
I have overloaded that operator in code as well I refuse to belive I need to pass all the members of the base class explicitly in the ctor
Last edited on
If you define your copy constructor to call itself...what do you think will happen if it keeps calling itself?
i tried defining the member expmicitly within the copy ctor still null pointer
I guess that it will call the assignment operator. But, ¿do you realize what you are doing?
You are setting your members, and later overriding them. I would like to see your assignment operator.

However there is no need to create a trivial copy constructor. The compiler already does that.

For the other class you should do
1
2
3
4
5
6
7
8
9
10
employee2::employee2(employee1& copy,
string _responsedate,string _application,string _resume,bool _callback,string _notes):
  employee1(copy), //'construct the parent'
  responsedate(_responsedate),
  application(_application),
  resume(_resume),
  callback(_callback)
{
  //...
} 
this doest solve the problem of not not being able to decalre a default employee2 e2; null pointer error
¿Could you please provide a minimal example that reproduces your issue?
Topic archived. No new replies allowed.