S
S.Senthilvel
hi,
I am a little confused about the const_cast.I've thought it this way till
now.
//Proper cast
int i = 10;
const int* pci = &i;
int *pi = const_cast<int*>(pci);
// Undefined cast
const int ci = 10;
const int* pci = &ci;
int *pi = const_cast<int*>(pci);
I thought that the result of a const_cast is undefined if the
object pointed to is really a constant.(or is it that modifying that result
is undefined)
In "More Effective C++" , I saw a piece of code which goes this way
class SpecialWidget;
void update(SpecialWidget* psw);
const SpecialWidget sw;
update(const_cast<SpecialWidget*>(&sw));
Here Meyers says that sw can now be safely updated inside "update" function.
I fell this is contradictory to what i have understood.
Can anyone kindly explain.
Thanks,
Senthilvel.
I am a little confused about the const_cast.I've thought it this way till
now.
//Proper cast
int i = 10;
const int* pci = &i;
int *pi = const_cast<int*>(pci);
// Undefined cast
const int ci = 10;
const int* pci = &ci;
int *pi = const_cast<int*>(pci);
I thought that the result of a const_cast is undefined if the
object pointed to is really a constant.(or is it that modifying that result
is undefined)
In "More Effective C++" , I saw a piece of code which goes this way
class SpecialWidget;
void update(SpecialWidget* psw);
const SpecialWidget sw;
update(const_cast<SpecialWidget*>(&sw));
Here Meyers says that sw can now be safely updated inside "update" function.
I fell this is contradictory to what i have understood.
Can anyone kindly explain.
Thanks,
Senthilvel.