On Thursday 31 July 2014, al davis wrote:
> clone() makes a copy of itself.
more info ....
clone is always defined something like this:
class FOO : public SOME_BASE {
//////
//////
SOME_BASE* clone()const {return new FOO(*this);}
/////
};
I might use it like this:
int main()
{
FOO aa;
FOO* bb = aa.clone();
// now I have two of them
}
Since it is just a wrapper for the copy constructor, why not
just use the copy constructor directly?
Answer, because I really don't know exactly what type to copy.
clone() is virtual.
So I might have:
int main()
{
CARD* prototype = device_dispatcher["resistor"];
CARD* an_instance = prototype.clone();
CARD* another_instance = prototype.clone();
// or I could use the short form:
CARD* yet_another = device_dispatcher.clone("capacitor");
}
_______________________________________________
Gnucap-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/gnucap-devel