get classname in static member
number
putimalitze at gmx.de
Wed Mar 28 09:44:35 UTC 2018
Is there a way to get the classname without specifying the class
in the first place as required by classinfo and
fullyQualifiedName? extracting it from __FUNCTION__ wouldn't work
outside a function, i.e. for a classfield, and 'this' doesn't
work in static members.
It's just about simple debugging like 'writeln(<classname>, ":
message: ..")' ..and learning.
And could somebody explain to me why 'typeid(this).stringof' is
returning 'typeid(this)'?
I'm using dmd v2.078.3
```
import std.stdio;
void main() {
class C
{
static void foo()
{
writeln(__FUNCTION__); // test.main.C.foo
writeln(C.classinfo); // test.main.C
import std.traits; //
writeln(fullyQualifiedName!C); // test.main.C
}
void fuu()
{
writeln(this); // test.main.C
writeln(typeid(this)); // test.main.C
writeln(typeid(this).stringof); // typeid(this)
writeln(this.classinfo); // test.main.C
}
}
C.foo();
writeln();
C c = new C();
c.fuu;
}
```
More information about the Digitalmars-d-learn
mailing list