Talk About Network

Google





Programming > C - C++ Learning > Re: assigmnet o...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 6 Topic 4087 of 4400
Post > Topic >>

Re: assigmnet operator when class data members are immutable

by Francis Glassborow <francis.glassborow@[EMAIL PROTECTED] > Mar 30, 2008 at 11:43 AM

chuck wrote:
> Hello,
>  I have a class whose data members are constant.  So, default assignment

> will not happen.  I am trying to write and assignment operator method 
> that will allow assignment.
> 
> I think my assignment with the swap might be the right direction but I 
> am currrently stumped.
> Can anyone help with this assignment operator?

Why on Earth would you want to mess with a cl***** invariants in such a 
way. Note that the compiler 'knows' that the member variables are 
constant and can (in its view) cache them for use elsewhere. IOWs it 
does not need to go back to the object to look up the current value. So 
if you lie to the compiler and change it anyway your code is 
fundamentally flawed.

This follows a basic rule that any time you declare a variable as const 
at top level any attempt to change its value leads to undefined behaviour.
 




 6 Posts in Topic:
assigmnet operator when class data members are immutable
chuck <noemail@[EMAIL   2008-03-29 19:10:49 
Re: assigmnet operator when class data members are immutable
Ian Collins <ian-news@  2008-03-30 13:51:10 
Re: assigmnet operator when class data members are immutable
Ulrich Eckhardt <dooms  2008-03-30 07:51:32 
Re: assigmnet operator when class data members are immutable
Francis Glassborow <fr  2008-03-30 11:38:49 
Re: assigmnet operator when class data members are immutable
Ulrich Eckhardt <dooms  2008-03-30 18:18:38 
Re: assigmnet operator when class data members are immutable
Francis Glassborow <fr  2008-03-30 11:43:06 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 13:16:27 PST 2009.