Why can't we define re-assignable const reference variable?
Sergey Gromov
snake.scaly at gmail.com
Wed Feb 20 12:27:54 PST 2008
Janice Caron <caron800 at googlemail.com> wrote:
> On 20/02/2008, Sergey Gromov <snake.scaly at gmail.com> wrote:
> > The traditional usage of parentheses is this: foo(x). This means that a
> > function foo is applied to its argument x, and not applied to everything
> > else. You are probably talking about some different tradition. Please
> > clarify.
>
> Happy to.
>
> It's the exact same tradition, except that the function in question is
> called "const", not "foo". It takes a type as it's input (e.g int),
> and yeilds a type as its output (in this case const int).
I see, thank you. It's really natural to think of const() as of a type-
yielding function, sort of typeof(), which never came to my mind for
some reason.
But here is the caveat.
As I understand from your posts, you state that "const(C) x;", as well
as "const C x;", declares a variable of type (const C). But this is not
true. It actually declares a variable of type "const ref to const C".
Since declaration "C x;" declares x of type "ref to C", I seem to
automatically assume that a declaration is actually
C ref x;
and therefore "const(C) x;" is actually "const(C) ref x;" which gives a
variable x of type "ref to const C". A C++ habit, I presume. But it
doesn't mean it's a bad approach.
--
SnakE
More information about the Digitalmars-d
mailing list