refInt = ref int: how to achieve this? or is this a bug?
mw
mingwu at gmail.com
Wed Jun 17 21:27:01 UTC 2020
On Wednesday, 17 June 2020 at 20:47:59 UTC, Steven Schveighoffer
wrote:
> Essentially, your alias statement becomes:
>
> alias refInt = int;
>
> Which in itself is somewhat of a "feature", as storage classes
> that do not apply are ignored. Some may consider it a bug, but
> I haven't seen anyone attempt something like what you have, it
> sure seems like the compiler should complain.
I would consider it a bug, *even* C++ can handle this better :-)
i.e. no surprise to the programmer.
cat reft.cpp
----------------------
#include <stdio.h>
typedef int& refInt;
void f(refInt i) {
i = 456;
}
int main() {
int i = 123;
printf("%d\n", i);
f(i);
printf("%d\n", i);
}
----------------------
$ make reft
g++ reft.cpp -o reft
$ ./reft
123
456
More information about the Digitalmars-d
mailing list