A
Abubakar
Hi,
check the following code:
++++
class nodeinfo{};
nodeinfo * v1_proc1 ()
{
nodeinfo * ni= new nodeinfo();
return ni;
}
void v1_use_proc1()
{
nodeinfo * n = NULL;
n = v1_proc1 ();
// use n....
delete n;
}
++++
another version:
class nodeinfo{};
nodeinfo & v2_proc1 ()
{
nodeinfo * ni= new nodeinfo();
return *ni;
}
void v2_use_proc1()
{
nodeinfo * n = NULL;
n = &v2_proc1 ();
// use n....
delete n;
}
++++
I have checked the code and both versions seem to work fine. My intention
here is that I call proc1() and get a new object of type nodeinfo and start
working with it and delete it when I'm done. Ultimately I want to use this
code concept in a class to offer Clone() functionality. What it would do is
create a new class if its own type and set all the private and public
properties and return a reference or pointer (or whatever!!).
Are these same or they have differences? I mean I can just use first one or
second, and both will give me the same functionality?
Regards,
Ab.
check the following code:
++++
class nodeinfo{};
nodeinfo * v1_proc1 ()
{
nodeinfo * ni= new nodeinfo();
return ni;
}
void v1_use_proc1()
{
nodeinfo * n = NULL;
n = v1_proc1 ();
// use n....
delete n;
}
++++
another version:
class nodeinfo{};
nodeinfo & v2_proc1 ()
{
nodeinfo * ni= new nodeinfo();
return *ni;
}
void v2_use_proc1()
{
nodeinfo * n = NULL;
n = &v2_proc1 ();
// use n....
delete n;
}
++++
I have checked the code and both versions seem to work fine. My intention
here is that I call proc1() and get a new object of type nodeinfo and start
working with it and delete it when I'm done. Ultimately I want to use this
code concept in a class to offer Clone() functionality. What it would do is
create a new class if its own type and set all the private and public
properties and return a reference or pointer (or whatever!!).
Are these same or they have differences? I mean I can just use first one or
second, and both will give me the same functionality?
Regards,
Ab.