tupleof for inherited classes.
mrdarksys
mrdarksys at gmail.com
Tue Jul 24 22:42:33 PDT 2012
[Problem]
How can I use enumFields() function of Engine class for enumerate
all fields of inherited classes?
I want to do without templates if possibly.
Code [example]:
//============
import std.stdio;
class Engine
{
public:
int publicField;
void enumFields()
{
writeln("Engine prints:");
foreach(ref field; this.tupleof)
writeln(field);
}
private:
bool privateField;
protected:
string protectedField = "s";
}
class Some : Engine
{
public:
int oneMoreField = 11;
void enumFields2()
{
writeln("Some prints:");
foreach(field; this.tupleof)
writeln(field);
}
protected:
string protectedField = "o";
}
int main()
{
auto objE = new Engine();
auto objS = new Some();
objE.enumFields();
objS.publicField = 4;
objS.enumFields();
objS.enumFields2();
return 0;
}
//==============
[Actual] output is:
//==============
Engine prints:
0
false
s
Engine prints:
4
false
s
Some prints:
11
o
//==============
[Expected] output is:
//==============
Engine prints:
0
false
s
Engine prints:
4
false
o
11
Some prints:
4
false
o
11
//==============
More information about the Digitalmars-d-learn
mailing list