Polymorphism? Passing arguments

Martin martin at mab-on.net
Sat Nov 4 01:22:05 UTC 2017


I have a interface
`interface Node {...}`

and some classes implementing Node:
```
class Text : Node {...}
class Element : Node {...}
```
and a function like this:
`public void setRelation(ref Node parent , ref Node child) {...}`

if i do this it works:
```
Node root = new Element("root");
Node text = new Text("blah");
setRelation(root ,  text);
```

but this does not:
```
Node root = new Element("root");
setRelation(root , new Text("blah"));
```
>Error: function Nodes.setRelation (ref Node parent, ref Node 
>child) is not callable using argument types (Node, Text)

Why is this? Text implements Node. This is how i do it in other 
Languages - How can would be this possible in D?


More information about the Digitalmars-d-learn mailing list