get classname in static member
number
putimalitze at gmx.de
Wed Mar 28 10:48:24 UTC 2018
On Wednesday, 28 March 2018 at 10:10:19 UTC, Simen Kjærås wrote:
> So to get the class name you'd generally use
> typeof(this).stringof.
>
> ...
>
>> And could somebody explain to me why 'typeid(this).stringof'
>> is returning 'typeid(this)'?
>
> Because that's what you're asking for. :p
>
> typeid returns the run-time (also called dynamic) type of a
> class instance. stringof is a compile-time construct that
> resolves to a compile-time constant string representation of
> its argument. If that argument is a type, it gives the name of
> the type. If it's an expression (such as 1+2, foo(), or
> typeid(this)), it gives a string representation of the
> expression. For typeid(this), that's "typeid(this)".
>
> If you want to know the dynamic type of a class reference at
> run-time, such as in fuu(), you'd need to write
> writeln(typeid(this)).
>
> --
> Simen
On Wednesday, 28 March 2018 at 10:12:34 UTC, bauss wrote:
> On Wednesday, 28 March 2018 at 09:44:35 UTC, number wrote:
>> And could somebody explain to me why 'typeid(this).stringof'
>> is returning 'typeid(this)'?
>
> stringof will return a string equivalent to the expression or
> symbol's representation, not its definition.
>
> Meaning:
>
> (212 + 221).stringof == "212 + 221"
>
> (new Foo).stringof == "new Foo"
>
> etc.
Thank you for the explanations. I somehow forgot about typeof
though i must have seen it a lot in 'Ali Cehreli's Book.
More information about the Digitalmars-d-learn
mailing list