www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can't seemed to get parent name from a class at compile time.

reply 12345swordy <alexanderheistermann gmail.com> writes:
import std.stdio;

class bob
{
}
class tom : bob
{
}
void main()
{
     writeln(__traits(identifier,__traits(parent,tom)));
}


Am I doing this right? I am expecting it to print "bob".
Dec 15 2017
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Friday, 15 December 2017 at 17:16:41 UTC, 12345swordy wrote:
 Am I doing this right? I am expecting it to print "bob".
parent gets the container of the symbol (in this case, the module), not the inheritance list. You probably want BaseClassesTuple!tom[0] instead, which is the class it inherits from. import std.traits for that. http://dpldocs.info/experimental-docs/std.traits.BaseClassesTuple.html
Dec 15 2017