Re: Self Assignment check in Copy ctor
From: Risto Lankinen (rlankine_at_hotmail.com)
Date: 02/06/05
- Previous message: mosfets_at_gmail.com: "classes, pointers, vectors, and memory allocation"
- In reply to: Artie Gold: "Re: Self Assignment check in Copy ctor"
- Next in thread: Clark S. Cox III: "Re: Self Assignment check in Copy ctor"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 5 Feb 2005 23:37:10 -0800
> AlgoMan wrote:
> > Do you need to provide a self assignment check in a copy ctor
> > (like you provide in an assignment operator).
Artie Gold <artiegold@austin.rr.com> wrote in message news:<36ktrvF50haq3U1@individual.net>...
> Two words: What `self'?
Well, you know, the... the... the 'self':
- - -
struct C
{
C( const C &r )
{
if( this == &r )
{
cout << "Hello myself!" << endl;
}
}
};
int main()
{
C c(c);
}
- - -
(Go ahead, try it out if you don't believe it works!)
> AlgoMan wrote:
> > If not, why not?
Because the risk is very very small that somebody would
accidentally copy-initialize with reference to self. It
can be done, but the only way to do it is deliberately.
- Risto -
- Previous message: mosfets_at_gmail.com: "classes, pointers, vectors, and memory allocation"
- In reply to: Artie Gold: "Re: Self Assignment check in Copy ctor"
- Next in thread: Clark S. Cox III: "Re: Self Assignment check in Copy ctor"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|