I am trying to make something like:
type
Graph = ref object of RootObj
Circle = ref object of Graph
Polygon = ref object of Graph
proc isCircle(o: Graph): bool = #...
But it seems typeinfo supports only base system type, and typetraits always get "Graph"?I can think of two ways you can do it:
type
Graph = ref object of RootObj
Circle = ref object of Graph
Polygon = ref object of Graph
proc newCircle: Circle =
new result
proc newPolygon: Polygon =
new result
proc isCircle(o: Graph): bool =
result = o of Circle
method isCircle2(o: Graph): bool = false
method isCircle2(o: Circle): bool = true
var
c = newCircle()
p = newPolygon()
echo c.isCircle # true
echo p.isCircle # false
echo c.isCircle2 # true
echo p.isCircle2 # false