Re: clone
Originally posted by mamio
Hi,
- clone is usually implemented as returning a pointer to the cloned object. Is it correct to have it return a reference instead?
A related question is:
- If X is a reference to an object. Is it correct to write
delete &X? I mean, is &X technically a pointer?
Syntactically, it's fine. Semantically, you could be in big trouble:
Code:
int i;
int * j = new int;
int &ri = i;
int &rj = *j;
delete &rj; // OK (I'm fairly sure...)
delete &ri; // Oops!
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell