Considering the code
(1) Fruit f1{"Orange"};
(2) Fruit f2{"Lemmon"};
(3) const Fruit ff = f1;
(4) ff = f2;
C++ compiler complains at line (4) that Fruit
cannot be assigned to const Fruit
. But if I write
(1) Fruit f1{"Orange"};
(2) Fruit f2{"Lemmon"};
(3) const Fruit* ff = &f1;
(4) ff = &f2;
why doesn't the compiler complain at line (4) that Fruit*
cannot be assigned to const Fruit*
?