N
nrhayyal
hi all,
is it a good idea to assign object to pointers without initialising it
to NULL?
suppose if i have a class TEST
class ELEMENT
{
private:
int a;
string s1;
public:
func(a);
AddChild()
{
cout<<"some value";
}
};
i have object of TEST as shown below:
ELEMENT *inventors=biblio->AddChild("Invs");
ELEMENT *t2;
is it better to initialize while declaring itself?
i mean,if i say :
ELEMENT *t2= inventors->AddChild("Inv");// is this safe enough?
or do i need to go with usual conventions like:
ELEMENT *t2=NULL;
t2= inventors->AddChild("Inv");
so please help me which one is better and safe?
if not please explain me what could go wrong with
ELEMENT *t2= inventors->AddChild("Inv");
thanks & regards
Nagaraj Hayyal
is it a good idea to assign object to pointers without initialising it
to NULL?
suppose if i have a class TEST
class ELEMENT
{
private:
int a;
string s1;
public:
func(a);
AddChild()
{
cout<<"some value";
}
};
i have object of TEST as shown below:
ELEMENT *inventors=biblio->AddChild("Invs");
ELEMENT *t2;
is it better to initialize while declaring itself?
i mean,if i say :
ELEMENT *t2= inventors->AddChild("Inv");// is this safe enough?
or do i need to go with usual conventions like:
ELEMENT *t2=NULL;
t2= inventors->AddChild("Inv");
so please help me which one is better and safe?
if not please explain me what could go wrong with
ELEMENT *t2= inventors->AddChild("Inv");
thanks & regards
Nagaraj Hayyal