Get identifier of "this"
Jonathan M Davis
jmdavisProg at gmx.com
Mon Sep 17 10:49:34 PDT 2012
On Monday, September 17, 2012 19:43:24 Andre wrote:
> Hi,
>
> assuming I have following constuct:
>
> public class Bank{
> public enum test()
> {
> return "writeln(\""~__traits(identfier, this)~"\");";
> }
> }
>
> public static void main(){
> Bank b = new Bank;
> mixin(b.test());
> }
>
> During compile time, following code should be generated:
> writeln("b");
>
> Is this possible? For the demo coding I receive the error, that
> "this"
> has no identifier.
No. It's not possible. __traits is a compile-time construct, and Bank's
definition knows nothing about any variables of type Bank declared elsewhere.
Heck, the code for Bank could be compiled months before the code with b in it
is even written (and then has the code with Bank linked to it when it's
compiled). So no, it can't know about b, and what you're trying to do won't
work.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list