Const sucks

Janice Caron caron800 at googlemail.com
Tue Sep 11 11:03:41 PDT 2007


On 9/11/07, Nathan Reed <nathaniel.reed at gmail.com> wrote:

> > Then just decree that it be illegal to take the address of a const
> > class member variable. Problem solved.
>
> That places totally unnecessary restrictions on the programmer...there's
> absolutely no reason why you shouldn't be able to take the address of
> something const.

Remember, this is a special circumstance - /as a class member variable/

Consider:

class C
{
    const int n = 42;
    /* other stuff */
}

Suppose you new a thousand of those things. What's the point of making
a thousand ints, all the same. Why not just do:

class C
{
    static const int n = 42;
    /* other stuff */
}

and only consume four bytes.

I argue that per-class-instance const variables is so silly, that you
might just as well let the compiler "disappear" them.



> It's not /my/ macro idea. :)

My apologies. I lost track of to whom I was replying.

> Although, as other
> people have pointed out, this doesn't break type safety, just makes the
> type not explicitly stated in the code.

And this is different to #define how exactly?



More information about the Digitalmars-d mailing list