How polymorphism work in D?
OiseuKodeur
oiseaukodeur at gmail.com
Wed Nov 6 05:43:42 UTC 2019
I have this
```
import std.stdio : writeln;
abstract class Foo { }
class Bar : Foo
{
float value;
this(float t_value) { value = t_value; }
}
class Baz : Foo
{
string name;
this(string t_name) { name = t_name; }
}
void main()
{
Foo foo = new Bar(10);
if (/* typeof foo == Bar */)
foo.value.writeln;
else if (/* typeof foo == Baz */)
foo.name.writeln;
foo.writeln;
}
```
I don't understand how i can differentiate between Bar and Baz
and to get their attributes
More information about the Digitalmars-d-learn
mailing list