By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

Self Assignment check in Copy ctor

P: n/a
Do you need to provide a self assignment check in a copy ctor
(like you provide in an assignment operator).

If not, why not?

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
AlgoMan wrote:
Do you need to provide a self assignment check in a copy ctor
(like you provide in an assignment operator).

If not, why not?

<sarcasm>
"Do you smell something?"

"Yeah."

"What is it?"

"Wait...it's, it's..."

"Yup. Smells like homework to me..."

"Me too."
</sarcasm>

Two words: What `self'?

HTH,
--ag
--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Jul 23 '05 #2

P: n/a
On 2005-02-05 16:45:27 -0500, "AlgoMan" <al*****@mailinator.com> said:
Do you need to provide a self assignment check in a copy ctor
(like you provide in an assignment operator).

If not, why not?


Just think about it, what does a self assignment check actually check for?

--
Clark S. Cox, III
cl*******@gmail.com

Jul 23 '05 #3

P: n/a
> AlgoMan wrote:
Do you need to provide a self assignment check in a copy ctor
(like you provide in an assignment operator).

Artie Gold <ar*******@austin.rr.com> wrote in message news:<36*************@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 -
Jul 23 '05 #4

P: n/a
AlgoMan wrote:
Do you need to provide a self assignment check in a copy ctor
(like you provide in an assignment operator).

If not, why not?

It's possible to initialize an object with itself, but it's not overly
useful nor something most worry about. Assignment is another matter.

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.